Add suggestion for iterators in iterators
This commit is contained in:
parent
fe1bf8e05c
commit
a3db47ab6c
6 changed files with 62 additions and 4 deletions
8
src/test/ui/issues/issue-81584.fixed
Normal file
8
src/test/ui/issues/issue-81584.fixed
Normal 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<_>>();
|
||||
}
|
||||
8
src/test/ui/issues/issue-81584.rs
Normal file
8
src/test/ui/issues/issue-81584.rs
Normal 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<_>>();
|
||||
}
|
||||
14
src/test/ui/issues/issue-81584.stderr
Normal file
14
src/test/ui/issues/issue-81584.stderr
Normal 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`.
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue