-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove braces when fixing a nested use tree into a single item #123344
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
a58b963
to
47788ff
Compare
This comment has been minimized.
This comment has been minimized.
tests/ui/lint/unnecessary-qualification/lint-unnecessary-qualification-issue-121331.fixed
Outdated
Show resolved
Hide resolved
47788ff
to
2d3a9a5
Compare
All tests pass, this is ready for review. @rustbot ready |
@@ -2703,7 +2703,7 @@ pub enum UseTreeKind { | |||
/// `use prefix` or `use prefix as rename` | |||
Simple(Option<Ident>), | |||
/// `use prefix::{...}` | |||
Nested(ThinVec<(UseTree, NodeId)>), | |||
Nested { items: ThinVec<(UseTree, NodeId)>, span: Span }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could use a comment explaining what the span is for (the parentheses, I was told)
@pietroalbini told me he does feel like adding the comment later so I will approve this now. if adding the comment never happens, that's sad but ok too. @bors r+ |
} | ||
|
||
let mut unused_spans = Vec::new(); | ||
let mut to_remove = Vec::new(); | ||
let mut all_nested_unused = true; | ||
let mut used_childs = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we agreed to not talk about this one
…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.
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#123344 (Remove braces when fixing a nested use tree into a single item) - rust-lang#124587 (Generic `NonZero` post-stabilization changes.) - rust-lang#124775 (crashes: add lastest batch of crash tests) - rust-lang#124869 (Make sure we don't deny macro vars w keyword names) - rust-lang#124876 (Simplify `use crate::rustc_foo::bar` occurrences.) - rust-lang#124892 (Update cc crate to v1.0.97) - rust-lang#124903 (Ignore empty RUSTC_WRAPPER in bootstrap) - rust-lang#124909 (Reapply the part of rust-lang#124548 that bors forgot) r? `@ghost` `@rustbot` modify labels: rollup
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.
…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.
…s, r=Nilstrieb Followup fixes from rust-lang#123344 `@Nilstrieb` doesn't deserve [to be sad](rust-lang#123344 (comment)), so this PR addresses the two pieces of feedback from that PR. r? `@Nilstrieb`
…llaumeGomez Rollup of 3 pull requests Successful merges: - rust-lang#125261 (crashes: add more) - rust-lang#125270 (Followup fixes from rust-lang#123344) - rust-lang#125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
…s, r=Nilstrieb Followup fixes from rust-lang#123344 ``@Nilstrieb`` doesn't deserve [to be sad](rust-lang#123344 (comment)), so this PR addresses the two pieces of feedback from that PR. r? ``@Nilstrieb``
…mpiler-errors Rollup of 7 pull requests Successful merges: - rust-lang#123709 (Update documentation related to the recent cmd.exe fix) - rust-lang#124304 (revise the interpretation of ReadDir for HermitOS) - rust-lang#124708 (Actually use the `#[do_not_recommend]` attribute if present) - rust-lang#125252 (Add `#[inline]` to float `Debug` fallback used by `cfg(no_fp_fmt_parse)`) - rust-lang#125261 (crashes: add more) - rust-lang#125270 (Followup fixes from rust-lang#123344) - rust-lang#125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125270 - pietroalbini:pa-no-sad-contributors, r=Nilstrieb Followup fixes from rust-lang#123344 ``@Nilstrieb`` doesn't deserve [to be sad](rust-lang#123344 (comment)), so this PR addresses the two pieces of feedback from that PR. r? ``@Nilstrieb``
…llaumeGomez Rollup of 3 pull requests Successful merges: - rust-lang#125261 (crashes: add more) - rust-lang#125270 (Followup fixes from rust-lang#123344) - rust-lang#125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
…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.
Back in 2019 I added rustfix support for the
unused_imports
lint, to automatically remove them when runningcargo fix
. For the most part this worked great, but when removing all but one childs of a nested use tree it turneduse foo::{Unused, Used}
intouse foo::{Used}
. This is slightly annoying, because it then requires you to runrustfmt
to getuse 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 theunused_imports
lint. I created a test intests/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 fixingunused_lints
.This PR is best reviewed commit-by-commit.