forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#81939 - kper:fixing-81584-allocate-in-iter,…
… r=davidtwco Add suggestion `.collect()` for iterators in iterators Closes rust-lang#81584 ``` error[E0515]: cannot return value referencing function parameter `y` --> main3.rs:4:38 | 4 | ... .map(|y| y.iter().map(|x| x + 1)) | -^^^^^^^^^^^^^^^^^^^^^^ | | | returns a value referencing data owned by the current function | `y` is borrowed here | help: Maybe use `.collect()` to allocate the iterator ``` Added the suggestion: `help: Maybe use `.collect()` to allocate the iterator`
- Loading branch information
Showing
6 changed files
with
62 additions
and
4 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
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,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<_>>(); | ||
} |
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,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<_>>(); | ||
} |
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,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`. |
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