-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid ICE when referencing desugared local binding in borrow error
- Loading branch information
Showing
3 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |