1
Fork 0

Auto merge of #45922 - vramana:fix-45702, r=nikomatsakis

Fix MIR borrowck EndRegion not found

Fixes #45702

- [x] Add Tests
This commit is contained in:
bors 2017-11-15 04:48:16 +00:00
commit f93a4928c2
3 changed files with 44 additions and 14 deletions

View file

@ -125,12 +125,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
/// Returns the span for the "end point" given region. This will /// Returns the span for the "end point" given region. This will
/// return `None` if NLL is enabled, since that concept has no /// return `None` if NLL is enabled, since that concept has no
/// meaning there. Otherwise, it should return some. /// meaning there. Otherwise, return region span if it exists and
/// span for end of the function if it doesn't exist.
pub fn opt_region_end_span(&self, region: &Region) -> Option<Span> { pub fn opt_region_end_span(&self, region: &Region) -> Option<Span> {
let opt_span = self.region_span_map.get(region); match self.nonlexical_regioncx {
assert!(self.nonlexical_regioncx.is_some() || Some(_) => None,
opt_span.is_some(), "end region not found for {:?}", region); None => {
opt_span.map(|s| s.end_point()) match self.region_span_map.get(region) {
Some(span) => Some(span.end_point()),
None => Some(self.mir.span.end_point())
}
}
}
} }
/// Add all borrows to the kill set, if those borrows are out of scope at `location`. /// Add all borrows to the kill set, if those borrows are out of scope at `location`.

View file

@ -12,17 +12,29 @@
// conflicts with a new loan, as opposed to every issued loan. This keeps us // conflicts with a new loan, as opposed to every issued loan. This keeps us
// down to O(n) errors (for n problem lines), instead of O(n^2) errors. // down to O(n) errors (for n problem lines), instead of O(n^2) errors.
// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
fn main() { fn main() {
let mut x = 1; let mut x = 1;
let mut addr; let mut addr;
loop { loop {
match 1 { match 1 {
1 => { addr = &mut x; } 1 => { addr = &mut x; } //[ast]~ ERROR [E0499]
//~^ ERROR cannot borrow `x` as mutable more than once at a time //[mir]~^ ERROR (Ast) [E0499]
2 => { addr = &mut x; } //[mir]~| ERROR (Mir) [E0499]
//~^ ERROR cannot borrow `x` as mutable more than once at a time 2 => { addr = &mut x; } //[ast]~ ERROR [E0499]
_ => { addr = &mut x; } //[mir]~^ ERROR (Ast) [E0499]
//~^ ERROR cannot borrow `x` as mutable more than once at a time //[mir]~| ERROR (Mir) [E0506]
//[mir]~| ERROR (Mir) [E0499]
//[mir]~| ERROR (Mir) [E0499]
_ => { addr = &mut x; } //[ast]~ ERROR [E0499]
//[mir]~^ ERROR (Ast) [E0499]
//[mir]~| ERROR (Mir) [E0506]
//[mir]~| ERROR (Mir) [E0499]
//[mir]~| ERROR (Mir) [E0499]
} }
} }
} }

View file

@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir
enum Sexpression { enum Sexpression {
Num(()), Num(()),
Cons(&'static mut Sexpression) Cons(&'static mut Sexpression)
@ -15,9 +18,18 @@ enum Sexpression {
fn causes_ice(mut l: &mut Sexpression) { fn causes_ice(mut l: &mut Sexpression) {
loop { match l { loop { match l {
&mut Sexpression::Num(ref mut n) => {}, &mut Sexpression::Num(ref mut n) => {}, //[mir]~ ERROR (Mir) [E0384]
&mut Sexpression::Cons(ref mut expr) => { //~ ERROR cannot borrow `l.0` &mut Sexpression::Cons(ref mut expr) => { //[ast]~ ERROR [E0499]
l = &mut **expr; //~ ERROR cannot assign to `l` //[mir]~^ ERROR (Ast) [E0499]
//[mir]~| ERROR (Mir) [E0506]
//[mir]~| ERROR (Mir) [E0384]
//[mir]~| ERROR (Mir) [E0499]
l = &mut **expr; //[ast]~ ERROR [E0506]
//[mir]~^ ERROR (Ast) [E0506]
//[mir]~| ERROR (Mir) [E0506]
//[mir]~| ERROR (Mir) [E0506]
//[mir]~| ERROR (Mir) [E0499]
//[mir]~| ERROR (Mir) [E0499]
} }
}} }}
} }