Add suggestion for iterators in iterators

This commit is contained in:
Kevin Per 2021-02-09 17:18:28 +00:00
parent fe1bf8e05c
commit a3db47ab6c
6 changed files with 62 additions and 4 deletions

View file

@ -0,0 +1,8 @@
// run-rustfix
fn main() {
let _ = vec![vec![0, 1], vec![2]]
.into_iter()
.map(|y| y.iter().map(|x| x + 1).collect::<Vec<_>>())
//~^ ERROR cannot return value referencing function parameter `y`
.collect::<Vec<_>>();
}

View file

@ -0,0 +1,8 @@
// run-rustfix
fn main() {
let _ = vec![vec![0, 1], vec![2]]
.into_iter()
.map(|y| y.iter().map(|x| x + 1))
//~^ ERROR cannot return value referencing function parameter `y`
.collect::<Vec<_>>();
}

View file

@ -0,0 +1,14 @@
error[E0515]: cannot return value referencing function parameter `y`
--> $DIR/issue-81584.rs:5:22
|
LL | .map(|y| y.iter().map(|x| x + 1))
| -^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `y` is borrowed here
|
= help: use `.collect()` to allocate the iterator
error: aborting due to previous error
For more information about this error, try `rustc --explain E0515`.

View file

@ -40,6 +40,8 @@ LL | | statefn: &id(state1 as StateMachineFunc)
| | ------------------------------ temporary value created here
LL | | }
| |_____^ returns a value referencing data owned by the current function
|
= help: use `.collect()` to allocate the iterator
error: aborting due to 4 previous errors