Closed
Description
Given a situation where an iterator is constructed inside of a scope where the data is being returned, we currently emit:
error[E0515]: cannot return value referencing function parameter `y`
--> src/main.rs:4:18
|
4 | .map(|y| y.iter().map(|x| x + 1))
| -^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `y` is borrowed here
We should suggest using .collect()
in these cases.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: IteratorsArea: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint; hard to understand for new users.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.