Skip to content
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

Add suggestion .collect() for iterators in iterators #81939

Merged
merged 1 commit into from
Mar 5, 2021

Conversation

kper
Copy link
Contributor

@kper kper commented Feb 9, 2021

Closes #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

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 9, 2021
@jyn514 jyn514 added A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2021
@rust-log-analyzer

This comment has been minimized.

@kper
Copy link
Contributor Author

kper commented Feb 11, 2021

@jyn514
borrow.borrowed_place.ty() does not work, because it returns Vec<i32> and not the iterators' map struct. I use self.regioncx.universal_regions().unnormalized_output_ty instead.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm of mixed feelings regarding this PR because of the suggestion applying to static-reference-to-fn-2.rs but given that the span isn't shown and the suggestion is marked as potentially incorrect, I guess it's fine. I'll approve once you squash your commits :)

@davidtwco davidtwco added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2021
@kper kper force-pushed the fixing-81584-allocate-in-iter branch 2 times, most recently from f968e9b to 553b513 Compare February 23, 2021 07:14
@kper
Copy link
Contributor Author

kper commented Feb 23, 2021

Thanks, I squashed it :)

@bors
Copy link
Contributor

bors commented Feb 23, 2021

☔ The latest upstream changes (presumably #82443) made this pull request unmergeable. Please resolve the merge conflicts.

@kper kper force-pushed the fixing-81584-allocate-in-iter branch from 553b513 to a3db47a Compare February 24, 2021 07:08
@davidtwco
Copy link
Member

Thanks, apologies for the delay in approving.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 4, 2021

📌 Commit a3db47a has been approved by davidtwco

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 4, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request 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 pull request 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`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#80723 (Implement NOOP_METHOD_CALL lint)
 - rust-lang#80763 (resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint)
 - rust-lang#81136 (Improved IO Bytes Size Hint)
 - rust-lang#81939 (Add suggestion `.collect()` for iterators in iterators)
 - rust-lang#82289 (Fix underflow in specialized ZipImpl::size_hint)
 - rust-lang#82728 (Avoid unnecessary Vec construction in BufReader)
 - rust-lang#82764 (Add {BTreeMap,HashMap}::try_insert)
 - rust-lang#82770 (Add assert_matches macro.)
 - rust-lang#82773 (Add diagnostic item to `Default` trait)
 - rust-lang#82787 (Remove unused code from main.js)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 20887b7 into rust-lang:master Mar 5, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect iterators going out of scope and suggest collecting
7 participants