Skip to content

Commit f93a492

Browse files
committed
Auto merge of #45922 - vramana:fix-45702, r=nikomatsakis
Fix MIR borrowck EndRegion not found Fixes #45702 - [x] Add Tests
2 parents 8a98531 + fbb7df0 commit f93a492

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
125125

126126
/// Returns the span for the "end point" given region. This will
127127
/// return `None` if NLL is enabled, since that concept has no
128-
/// meaning there. Otherwise, it should return some.
128+
/// meaning there. Otherwise, return region span if it exists and
129+
/// span for end of the function if it doesn't exist.
129130
pub fn opt_region_end_span(&self, region: &Region) -> Option<Span> {
130-
let opt_span = self.region_span_map.get(region);
131-
assert!(self.nonlexical_regioncx.is_some() ||
132-
opt_span.is_some(), "end region not found for {:?}", region);
133-
opt_span.map(|s| s.end_point())
131+
match self.nonlexical_regioncx {
132+
Some(_) => None,
133+
None => {
134+
match self.region_span_map.get(region) {
135+
Some(span) => Some(span.end_point()),
136+
None => Some(self.mir.span.end_point())
137+
}
138+
}
139+
}
134140
}
135141

136142
/// Add all borrows to the kill set, if those borrows are out of scope at `location`.

src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,29 @@
1212
// conflicts with a new loan, as opposed to every issued loan. This keeps us
1313
// down to O(n) errors (for n problem lines), instead of O(n^2) errors.
1414

15+
// revisions: ast mir
16+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
17+
1518
fn main() {
1619
let mut x = 1;
1720
let mut addr;
1821
loop {
1922
match 1 {
20-
1 => { addr = &mut x; }
21-
//~^ ERROR cannot borrow `x` as mutable more than once at a time
22-
2 => { addr = &mut x; }
23-
//~^ ERROR cannot borrow `x` as mutable more than once at a time
24-
_ => { addr = &mut x; }
25-
//~^ ERROR cannot borrow `x` as mutable more than once at a time
23+
1 => { addr = &mut x; } //[ast]~ ERROR [E0499]
24+
//[mir]~^ ERROR (Ast) [E0499]
25+
//[mir]~| ERROR (Mir) [E0499]
26+
2 => { addr = &mut x; } //[ast]~ ERROR [E0499]
27+
//[mir]~^ ERROR (Ast) [E0499]
28+
//[mir]~| ERROR (Mir) [E0506]
29+
//[mir]~| ERROR (Mir) [E0499]
30+
//[mir]~| ERROR (Mir) [E0499]
31+
_ => { addr = &mut x; } //[ast]~ ERROR [E0499]
32+
//[mir]~^ ERROR (Ast) [E0499]
33+
//[mir]~| ERROR (Mir) [E0506]
34+
//[mir]~| ERROR (Mir) [E0499]
35+
//[mir]~| ERROR (Mir) [E0499]
2636
}
2737
}
2838
}
39+
40+

src/test/compile-fail/issue-25579.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
13+
1114
enum Sexpression {
1215
Num(()),
1316
Cons(&'static mut Sexpression)
1417
}
1518

1619
fn causes_ice(mut l: &mut Sexpression) {
1720
loop { match l {
18-
&mut Sexpression::Num(ref mut n) => {},
19-
&mut Sexpression::Cons(ref mut expr) => { //~ ERROR cannot borrow `l.0`
20-
l = &mut **expr; //~ ERROR cannot assign to `l`
21+
&mut Sexpression::Num(ref mut n) => {}, //[mir]~ ERROR (Mir) [E0384]
22+
&mut Sexpression::Cons(ref mut expr) => { //[ast]~ ERROR [E0499]
23+
//[mir]~^ ERROR (Ast) [E0499]
24+
//[mir]~| ERROR (Mir) [E0506]
25+
//[mir]~| ERROR (Mir) [E0384]
26+
//[mir]~| ERROR (Mir) [E0499]
27+
l = &mut **expr; //[ast]~ ERROR [E0506]
28+
//[mir]~^ ERROR (Ast) [E0506]
29+
//[mir]~| ERROR (Mir) [E0506]
30+
//[mir]~| ERROR (Mir) [E0506]
31+
//[mir]~| ERROR (Mir) [E0499]
32+
//[mir]~| ERROR (Mir) [E0499]
2133
}
2234
}}
2335
}

0 commit comments

Comments
 (0)