rust/compiler/rustc_resolve/src
Matthias Krüger d30af5e168
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.
2024-05-08 23:33:24 +02:00
..
diagnostics Implement the unused_macro_rules lint 2022-05-05 19:13:00 +02:00
late delegation: Support async, const, extern "ABI" and C-variadic functions 2024-04-23 23:05:39 +03:00
build_reduced_graph.rs Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
check_unused.rs remove braces when fixing a nested use tree into a single use 2024-04-14 18:45:30 +02:00
def_collector.rs Add StaticForeignItem and use it on ForeignItemKind 2024-04-29 13:15:51 -03:00
diagnostics.rs Add raw identifier in a typo suggestion 2024-04-29 15:02:12 +08:00
effective_visibilities.rs Delegation implementation: step 1 2024-01-12 14:11:16 +03:00
errors.rs Move "elided lifetime in path" to subdiagnostic struct 2024-04-21 07:45:03 +00:00
ident.rs Fix f16 and f128 feature gates in editions other than 2015 2024-04-03 16:03:22 -04:00
imports.rs Silence unused_imports lint for redundant imports 2024-04-11 14:38:21 -04:00
late.rs Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
lib.rs Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-dead 2024-04-26 19:25:55 -04:00
macros.rs Ensure miri only uses fallback bodies that have manually been vetted to preserve all UB that the native intrinsic would have 2024-05-03 09:16:57 +00:00
rustdoc.rs Fix the assertion crash from rustdoc document indent widths 2024-04-28 11:17:09 +08:00