rust/compiler/rustc_builtin_macros/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
..
assert store the span of the nested part of the use tree in the ast 2024-04-14 18:45:28 +02:00
deriving Adjust some pubs. 2024-04-26 13:29:20 +10:00
format_foreign Use as_deref in compiler (but only where it makes sense) 2022-11-16 21:58:58 +00:00
alloc_error_handler.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
asm.rs Move some functions from rustc_expand to rustc_builtin_macros. 2024-04-26 09:24:33 +10:00
assert.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
cfg_accessible.rs compiler: fix few needless_pass_by_ref_mut clippy lints 2024-03-28 12:04:00 +03:00
cfg_eval.rs Remove extern crate tracing from numerous crates. 2024-04-30 16:47:49 +10:00
cfg.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
cmdline_attrs.rs Rename all ParseSess variables/fields/lifetimes as psess. 2024-03-05 08:11:45 +11:00
compile_error.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
concat_bytes.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
concat_idents.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
concat.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
derive.rs Introduce DeriveResolution. 2024-04-26 07:55:21 +10:00
edition_panic.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
env.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
errors.rs Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-dead 2024-04-26 19:25:55 -04:00
format_foreign.rs unwrap return Option value, as it always returns Some for some fns 2023-11-28 14:52:21 +03:00
format.rs Use parse renaming of rustc_parse_format. 2024-05-03 16:03:15 +10:00
global_allocator.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
lib.rs Remove extern crate tracing from numerous crates. 2024-04-30 16:47:49 +10:00
log_syntax.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
pattern_type.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
proc_macro_harness.rs Rename consuming chaining methods on DiagnosticBuilder. 2024-01-10 07:40:00 +11:00
source_util.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
standard_library_imports.rs Rename all ParseSess variables/fields/lifetimes as psess. 2024-03-05 08:11:45 +11:00
test_harness.rs Various improvements to entrypoint code 2024-05-04 14:48:42 +02:00
test.rs Remove extern crate tracing from numerous crates. 2024-04-30 16:47:49 +10:00
trace_macros.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00
util.rs Adjust some pubs. 2024-04-26 13:29:20 +10:00