about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRamana Venkata <vramana@users.noreply.github.com>2017-11-11 02:52:39 +0530
committerRamana Venkata <vramana@users.noreply.github.com>2017-11-11 04:40:23 +0530
commitfbb7df0f8256fcffb0143dd6424e2bd494fbb6da (patch)
tree1951d394fb9092b8bcfd32cdcf9cce7d4ae9faeb /src
parent563dc5171fd5d96f9714b4e722ad1d80a25f1dba (diff)
downloadrust-fbb7df0f8256fcffb0143dd6424e2bd494fbb6da.tar.gz
rust-fbb7df0f8256fcffb0143dd6424e2bd494fbb6da.zip
Fix MIR borrowck EndRegion not found
Updated tests

Fixes #45702
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/dataflow/impls/borrows.rs16
-rw-r--r--src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs24
-rw-r--r--src/test/compile-fail/issue-25579.rs18
3 files changed, 44 insertions, 14 deletions
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs
index e8bf543b70b..928c07b7fbc 100644
--- a/src/librustc_mir/dataflow/impls/borrows.rs
+++ b/src/librustc_mir/dataflow/impls/borrows.rs
@@ -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`.
diff --git a/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs b/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs
index 38e0e27a7b9..d4e9ab99ede 100644
--- a/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs
+++ b/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs
@@ -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]
         }
     }
 }
+
+
diff --git a/src/test/compile-fail/issue-25579.rs b/src/test/compile-fail/issue-25579.rs
index 323ce3b0adf..7da80d2852e 100644
--- a/src/test/compile-fail/issue-25579.rs
+++ b/src/test/compile-fail/issue-25579.rs
@@ -8,6 +8,9 @@
 // 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)
@@ -15,9 +18,18 @@ enum 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]
         }
     }}
 }