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

Initial implementation of rustfixable unused_imports lint #56645

Merged
merged 2 commits into from
Feb 11, 2019

Conversation

pietroalbini
Copy link
Member

@pietroalbini pietroalbini commented Dec 9, 2018

This PR adds the initial implementation of rustfixable unused_imports lint. The implementation works, but rustfix is not able to apply all the suggestions until #53934 is fixed. It also needs #58296 to hide the suggested note since it's really useless.

cc #47888

cargo fix in action on the unused_imports lint

screenshot from 2018-12-09 15-49-01

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(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 Dec 9, 2018
@pietroalbini pietroalbini added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2018
@rust-highfive

This comment has been minimized.

@euclio
Copy link
Contributor

euclio commented Dec 9, 2018

cc #47888

@bors
Copy link
Contributor

bors commented Dec 26, 2018

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

@pietroalbini
Copy link
Member Author

r? @estebank

@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor

estebank commented Feb 8, 2019

CC #58296

@zackmdavis
Copy link
Member

This isn't literally blocked on the #53934 mess (latest comment), is it? Like, the main reason we want this is to make the unused imports rustfix-able, but landing this structured suggestion (with the "remove the whole use item" and "remove the unused import" notes) doesn't hurt.

@estebank
Copy link
Contributor

estebank commented Feb 8, 2019

@pietroalbini I'm fine with merging this PR as is, as we at least have the visual output tests. We can revisit the tests once rustfix is rustfixed to rustfix these suggestions. r=me (rename beforehand) if you feel it's ready on your end.

@pietroalbini pietroalbini changed the title [WIP] Enable cargo fix for the unused_imports lint Initial implementation of rustfixable unused_imports lint Feb 8, 2019
@pietroalbini pietroalbini added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Feb 8, 2019
@pietroalbini
Copy link
Member Author

@bors r=estebank

@pietroalbini pietroalbini reopened this Feb 8, 2019
@pietroalbini
Copy link
Member Author

@bors r=estebank pls

@bors
Copy link
Contributor

bors commented Feb 8, 2019

📌 Commit 5ef7150 has been approved by estebank

@bors
Copy link
Contributor

bors commented Feb 9, 2019

💔 Test failed - checks-travis

@rust-highfive

This comment has been minimized.

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 9, 2019
@kennytm kennytm 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 9, 2019
@estebank

This comment has been minimized.

@pietroalbini
Copy link
Member Author

Yay, cargo's test suite assumes unused_imports is unfixable, a pending fix is in rust-lang/cargo#6649.

@pietroalbini pietroalbini added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 10, 2019
@pietroalbini
Copy link
Member Author

#58358 updating cargo has been merged.

@bors retry

@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-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Feb 11, 2019
@bors
Copy link
Contributor

bors commented Feb 11, 2019

⌛ Testing commit 5ef7150 with merge 57d7cfc...

bors added a commit that referenced this pull request Feb 11, 2019
Initial implementation of rustfixable unused_imports lint

This PR adds the initial implementation of rustfixable `unused_imports` lint. The implementation works, but rustfix is not able to apply all the suggestions until #53934 is fixed. It also needs #58296 to hide the suggested note since it's really useless.

cc #47888

<details><summary><code>cargo fix</code> in action on the <code>unused_imports</code> lint</summary>

![screenshot from 2018-12-09 15-49-01](https://user-images.githubusercontent.com/2299951/49698874-3a026080-fbca-11e8-9bf1-24060b6c59c8.png)

</details>
@bors
Copy link
Contributor

bors commented Feb 11, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: estebank
Pushing 57d7cfc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 11, 2019
@bors bors merged commit 5ef7150 into rust-lang:master Feb 11, 2019
@pietroalbini pietroalbini deleted the fix-unused-imports branch February 11, 2019 13:21
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 8, 2024
…Nilstrieb

Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 8, 2024
…Nilstrieb

Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2024
Rollup merge of rust-lang#123344 - pietroalbini:pa-unused-imports, r=Nilstrieb

Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request May 11, 2024
Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang/rust#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request May 16, 2024
Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang/rust#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request May 24, 2024
Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang/rust#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
github-actions bot pushed a commit to ytmimi/rustfmt that referenced this pull request Jun 7, 2024
Remove braces when fixing a nested use tree into a single item

[Back in 2019](rust-lang/rust#56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants