Remove braces when fixing a nested use tree into a single item#123344
Merged
bors merged 5 commits intorust-lang:masterfrom May 8, 2024
Merged
Remove braces when fixing a nested use tree into a single item#123344bors merged 5 commits intorust-lang:masterfrom
bors merged 5 commits intorust-lang:masterfrom
Conversation
Collaborator
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
Collaborator
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
Collaborator
|
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
Member
Author
|
All tests pass, this is ready for review. @rustbot ready |
Noratrieb
reviewed
May 8, 2024
| Simple(Option<Ident>), | ||
| /// `use prefix::{...}` | ||
| Nested(ThinVec<(UseTree, NodeId)>), | ||
| Nested { items: ThinVec<(UseTree, NodeId)>, span: Span }, |
Member
There was a problem hiding this comment.
this could use a comment explaining what the span is for (the parentheses, I was told)
Member
|
@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+ |
Collaborator
Noratrieb
reviewed
May 8, 2024
| let mut unused_spans = Vec::new(); | ||
| let mut to_remove = Vec::new(); | ||
| let mut all_nested_unused = true; | ||
| let mut used_childs = 0; |
Member
There was a problem hiding this comment.
we agreed to not talk about this one
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.
This was referenced May 8, 2024
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 8, 2024
…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
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.
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
May 17, 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.
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
May 19, 2024
…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`
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 19, 2024
…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
compiler-errors
added a commit
to compiler-errors/rust
that referenced
this pull request
May 19, 2024
…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``
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 19, 2024
…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
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 19, 2024
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``
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 19, 2024
…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
calebcartwright
pushed a commit
to calebcartwright/rust
that referenced
this pull request
Jun 22, 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Back in 2019 I added rustfix support for the
unused_importslint, 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 runrustfmtto 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-rustfixtest for fixing theunused_importslint. 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.