Skip to content

Fix MIR borrowck EndRegion not found #45922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {

/// Returns the span for the "end point" given region. This will
/// 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> {
let opt_span = self.region_span_map.get(region);
assert!(self.nonlexical_regioncx.is_some() ||
opt_span.is_some(), "end region not found for {:?}", region);
opt_span.map(|s| s.end_point())
match self.nonlexical_regioncx {
Some(_) => None,
None => {
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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@
// 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.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

fn main() {
let mut x = 1;
let mut addr;
loop {
match 1 {
1 => { addr = &mut x; }
//~^ ERROR cannot borrow `x` as mutable more than once at a time
2 => { addr = &mut x; }
//~^ ERROR cannot borrow `x` as mutable more than once at a time
_ => { addr = &mut x; }
//~^ ERROR cannot borrow `x` as mutable more than once at a time
1 => { addr = &mut x; } //[ast]~ ERROR [E0499]
//[mir]~^ ERROR (Ast) [E0499]
//[mir]~| ERROR (Mir) [E0499]
2 => { addr = &mut x; } //[ast]~ ERROR [E0499]
//[mir]~^ ERROR (Ast) [E0499]
//[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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arielb1 -- is there an existing issue for these multiple reports? I didn't see anything obvious in the spreadsheet, seems like we should file one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}


18 changes: 15 additions & 3 deletions src/test/compile-fail/issue-25579.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// revisions: ast mir
//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

enum Sexpression {
Num(()),
Cons(&'static mut Sexpression)
}

fn causes_ice(mut l: &mut Sexpression) {
loop { match l {
&mut Sexpression::Num(ref mut n) => {},
&mut Sexpression::Cons(ref mut expr) => { //~ ERROR cannot borrow `l.0`
l = &mut **expr; //~ ERROR cannot assign to `l`
&mut Sexpression::Num(ref mut n) => {}, //[mir]~ ERROR (Mir) [E0384]
&mut Sexpression::Cons(ref mut expr) => { //[ast]~ ERROR [E0499]
//[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]
}
}}
}
Expand Down