about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-07-27 13:23:34 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-07-27 13:25:09 -0700
commitb523b2d51e74304ecacfca86bf60553c76ec1bf4 (patch)
treee112c4a4ac353c00a02e163b03c9600f2ad2e073
parent03f19f7ff128a3b01eeab3f87f04cce22883f006 (diff)
downloadrust-b523b2d51e74304ecacfca86bf60553c76ec1bf4.tar.gz
rust-b523b2d51e74304ecacfca86bf60553c76ec1bf4.zip
Avoid ICE when referencing desugared local binding in borrow error
-rw-r--r--src/librustc_mir/borrow_check/conflict_errors.rs25
-rw-r--r--src/test/ui/borrowck/issue-63026.rs18
-rw-r--r--src/test/ui/borrowck/issue-63026.stderr12
3 files changed, 42 insertions, 13 deletions
diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs
index 5d0e490ebea..77e5ac2f865 100644
--- a/src/librustc_mir/borrow_check/conflict_errors.rs
+++ b/src/librustc_mir/borrow_check/conflict_errors.rs
@@ -1140,19 +1140,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                 bug!("try_report_cannot_return_reference_to_local: not a local")
             };
             match self.body.local_kind(*local) {
-                LocalKind::ReturnPointer | LocalKind::Temp => {
-                    (
-                        "temporary value".to_string(),
-                        "temporary value created here".to_string(),
-                    )
-                }
-                LocalKind::Arg => {
-                    (
-                        "function parameter".to_string(),
-                        "function parameter borrowed here".to_string(),
-                    )
-                },
-                LocalKind::Var => bug!("local variable without a name"),
+                LocalKind::ReturnPointer | LocalKind::Temp => (
+                    "temporary value".to_string(),
+                    "temporary value created here".to_string(),
+                ),
+                LocalKind::Arg => (
+                    "function parameter".to_string(),
+                    "function parameter borrowed here".to_string(),
+                ),
+                LocalKind::Var => (
+                    "local binding".to_string(),
+                    "local binding introduced here".to_string(),
+                ),
             }
         };
 
diff --git a/src/test/ui/borrowck/issue-63026.rs b/src/test/ui/borrowck/issue-63026.rs
new file mode 100644
index 00000000000..86240a69148
--- /dev/null
+++ b/src/test/ui/borrowck/issue-63026.rs
@@ -0,0 +1,18 @@
+use std::collections::HashMap;
+use std::hash::Hash;
+
+fn group_by<I, F, T>(xs: &mut I, f: F) -> HashMap<T, Vec<&I::Item>>
+where
+    I: Iterator,
+    F: Fn(&I::Item) -> T,
+    T: Eq + Hash,
+{
+    let mut result = HashMap::new();
+    for ref x in xs {
+        let key = f(x);
+        result.entry(key).or_insert(Vec::new()).push(x);
+    }
+    result //~ ERROR cannot return value referencing local binding
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-63026.stderr b/src/test/ui/borrowck/issue-63026.stderr
new file mode 100644
index 00000000000..2289a03e014
--- /dev/null
+++ b/src/test/ui/borrowck/issue-63026.stderr
@@ -0,0 +1,12 @@
+error[E0515]: cannot return value referencing local binding
+  --> $DIR/issue-63026.rs:15:5
+   |
+LL |     for ref x in xs {
+   |                  -- local binding introduced here
+...
+LL |     result
+   |     ^^^^^^ returns a value referencing data owned by the current function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0515`.