]> git.lizzy.rs Git - rust.git/commitdiff
review comments
authorEsteban Küber <esteban@kuber.com.ar>
Sun, 28 Jul 2019 02:12:00 +0000 (19:12 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 28 Jul 2019 02:15:25 +0000 (19:15 -0700)
src/test/ui/borrowck/issue-63026.rs [deleted file]
src/test/ui/borrowck/issue-63026.stderr [deleted file]
src/test/ui/borrowck/return-local-binding-from-desugaring.rs [new file with mode: 0644]
src/test/ui/borrowck/return-local-binding-from-desugaring.stderr [new file with mode: 0644]

diff --git a/src/test/ui/borrowck/issue-63026.rs b/src/test/ui/borrowck/issue-63026.rs
deleted file mode 100644 (file)
index 86240a6..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-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
deleted file mode 100644 (file)
index 2289a03..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-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`.
diff --git a/src/test/ui/borrowck/return-local-binding-from-desugaring.rs b/src/test/ui/borrowck/return-local-binding-from-desugaring.rs
new file mode 100644 (file)
index 0000000..b2dcd54
--- /dev/null
@@ -0,0 +1,33 @@
+// To avoid leaking the names of local bindings from expressions like for loops, #60984
+// explicitly ignored them, but an assertion that `LocalKind::Var` *must* have a name would
+// trigger an ICE. Before this change, this file's output would be:
+// ```
+// error[E0515]: cannot return value referencing local variable `__next`
+//   --> return-local-binding-from-desugaring.rs:LL:CC
+//    |
+// LL |     for ref x in xs {
+//    |         ----- `__next` is borrowed here
+// ...
+// LL |     result
+//    |     ^^^^^^ returns a value referencing data owned by the current function
+// ```
+// FIXME: ideally `LocalKind` would carry more information to more accurately explain the problem.
+
+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/return-local-binding-from-desugaring.stderr b/src/test/ui/borrowck/return-local-binding-from-desugaring.stderr
new file mode 100644 (file)
index 0000000..293dbe6
--- /dev/null
@@ -0,0 +1,12 @@
+error[E0515]: cannot return value referencing local binding
+  --> $DIR/return-local-binding-from-desugaring.rs:30: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`.