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

Closure migration multispan suggestions #87958

Merged

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Aug 12, 2021

This changes the rust_2021_incompatible_closure_captures lint to only suggest inserting the parts that need to be inserted, instead of suggesting to replace the entire closure by an almost identical closure with one statement added.

Before:

[...]
help: add a dummy let to cause `a` to be fully captured
   |
5  ~     let _ = || {
6  +         let _ = &a;
7  +         dbg!(a.0);
8  +         println!("1");
9  +         println!("2");
10 +         println!("3");
 ...
   |

[...]
help: add a dummy let to cause `b` to be fully captured
   |
14 |     let _ = || { let _ = &b; dbg!(b.0); };
   |                ~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]
help: add a dummy let to cause `c` to be fully captured
   |
16 |     let _ = || { let _ = &c; dbg!(c.0) };
   |                ~~~~~~~~~~~~~~~~~~~~~~~~~

After:

[...]
help: add a dummy let to cause `a` to be fully captured
   |
5  ~     let _ = || {
6  +         let _ = &a;
   |

[...]
help: add a dummy let to cause `b` to be fully captured
   |
14 |     let _ = || { let _ = &b; dbg!(b.0); };
   |                  +++++++++++

[...]
help: add a dummy let to cause `c` to be fully captured
   |
16 |     let _ = || { let _ = &c; dbg!(c.0) };
   |                +++++++++++++           +

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(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 Aug 12, 2021
@m-ou-se m-ou-se added A-closures Area: closures (`|args| { .. }`) A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-edition Diagnostics: An error or lint that should account for edition differences. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 12, 2021
@bors
Copy link
Contributor

bors commented Aug 13, 2021

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

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 13, 2021
@m-ou-se m-ou-se force-pushed the closure-migration-multispan-suggestions branch from 02772dd to 6431097 Compare August 16, 2021 10:52
@m-ou-se m-ou-se marked this pull request as ready for review August 16, 2021 10:52
@m-ou-se m-ou-se added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 16, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 16, 2021

r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned cjgillot Aug 16, 2021
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

I feel it would be slightly easier to read if we had a single multpart_suggestion call and the branching logic got you the messages, applicability and necessary vector, but I'm not too bothered either way.

r=me with or without the suggested changes.

@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 16, 2021

I prefer calling it multiple times to avoid having to chase variables around, and to make it easier to make modifications to one of those cases later. E.g. using the _verbose or _short versions, or adding a note in a specific case, or adding a case in which there's no suggestion, etc.

@bors r=estebank

@bors
Copy link
Contributor

bors commented Aug 16, 2021

📌 Commit 6431097 has been approved by estebank

@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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 16, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#87178 ([rustdoc] Copy only item path to clipboard rather than full `use` statement.)
 - rust-lang#87677 (Adding explicit notice of lack of documentation for Tier 2 Platforms)
 - rust-lang#87958 (Closure migration multispan suggestions)
 - rust-lang#87967 (Detect fake spans in non_fmt_panic lint.)
 - rust-lang#88011 (Enable `--all-targets` for `x.py check` unconditionally)
 - rust-lang#88030 (Assign FIXMEs to me and remove obsolete ones)
 - rust-lang#88052 (Update redox_syscall)
 - rust-lang#88055 (Update RELEASES.md for 1.55.0)
 - rust-lang#88080 (Skip assert ICE with default_method_body_is_const)
 - rust-lang#88089 (Rustdoc font test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d7df1b1 into rust-lang:master Aug 17, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: closures (`|args| { .. }`) A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-edition Diagnostics: An error or lint that should account for edition differences. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

6 participants