Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jul 28, 2019
1 parent b523b2d commit 01ba0e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
18 changes: 0 additions & 18 deletions src/test/ui/borrowck/issue-63026.rs

This file was deleted.

33 changes: 33 additions & 0 deletions src/test/ui/borrowck/return-local-binding-from-desugaring.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local binding
--> $DIR/issue-63026.rs:15:5
--> $DIR/return-local-binding-from-desugaring.rs:30:5
|
LL | for ref x in xs {
| -- local binding introduced here
Expand Down

0 comments on commit 01ba0e3

Please sign in to comment.