-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect iterators going out of scope and suggest collecting #81584
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-iterators
Area: Iterators
A-lifetimes
Area: lifetime related
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
P-low
Low priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
estebank
added
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lifetimes
Area: lifetime related
P-low
Low priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
labels
Jan 31, 2021
Or flatten/flat_map? |
I want for us to detect cases of trying to operate on iterators of iterators because the only option then is to allocate or completely rework the logic. The former will help newcomers, experts will know enough to try the later. |
camelid
added
A-iterators
Area: Iterators
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
labels
Feb 1, 2021
@rustbot claim |
Couldn't we still recommend both? Recommending bad practices seems suboptimal. |
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
Mar 5, 2021
… 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`
m-ou-se
added a commit
to m-ou-se/rust
that referenced
this issue
Mar 5, 2021
… 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`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-iterators
Area: Iterators
A-lifetimes
Area: lifetime related
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
P-low
Low priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given a situation where an iterator is constructed inside of a scope where the data is being returned, we currently emit:
We should suggest using
.collect()
in these cases.The text was updated successfully, but these errors were encountered: