diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-08 23:33:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-08 23:33:24 +0200 |
| commit | eef082899d9b8f468da35f5d4b9e5784e435b07e (patch) | |
| tree | afcb014bdd4f95e8b3c915a6df48865be300c8ad /clippy_utils | |
| parent | 10913d27a13dd1997c2b2a48286f4968613d49b5 (diff) | |
| parent | f0f392781f2829aaf4368e28c2ba3e9bc0e6115f (diff) | |
| download | rust-eef082899d9b8f468da35f5d4b9e5784e435b07e.tar.gz rust-eef082899d9b8f468da35f5d4b9e5784e435b07e.zip | |
Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb
Remove braces when fixing a nested use tree into a single item
[Back in 2019](https://github.com/rust-lang/rust/pull/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.
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/ast_utils.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 529d20126b2..d3bbc66bcae 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -648,7 +648,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool { match (l, r) { (Glob, Glob) => true, (Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)), - (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), + (Nested { items: l, .. }, Nested { items: r, .. }) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), _ => false, } } |
