rust/compiler
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
..
rustc Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...` 2024-05-02 19:48:29 +02:00
rustc_abi Rollup merge of #124555 - Zalathar:init-coverage, r=nnethercote 2024-05-03 20:33:46 +02:00
rustc_arena rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
rustc_ast Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_ast_ir Remove `extern crate rustc_macros` from numerous crates. 2024-04-29 10:21:54 +10:00
rustc_ast_lowering Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_ast_passes Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
rustc_ast_pretty Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_attr Remove `extern crate rustc_macros` from numerous crates. 2024-04-29 10:21:54 +10:00
rustc_baked_icu_data
rustc_borrowck borrowck: more eagerly prepopulate opaques 2024-05-06 16:04:57 +00:00
rustc_builtin_macros Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_codegen_cranelift debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]` 2024-04-25 22:14:47 +03:00
rustc_codegen_gcc Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk 2024-05-03 17:41:48 +00:00
rustc_codegen_llvm Adjust 64-bit ARM data layouts for LLVM update 2024-05-06 16:53:17 +00:00
rustc_codegen_ssa Auto merge of #124858 - alexcrichton:some-wasi-changes, r=michaelwoerister 2024-05-08 11:39:26 +00:00
rustc_const_eval replace another Option<Span> by DUMMY_SP 2024-05-07 14:52:42 +02:00
rustc_data_structures Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk 2024-05-03 17:41:48 +00:00
rustc_driver
rustc_driver_impl compiler: upgrade time from 0.3.34 to 0.3.36 2024-05-04 21:18:41 -07:00
rustc_error_codes Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
rustc_error_messages Rename `SubdiagnosticMessage` as `SubdiagMessage`. 2024-03-05 12:14:49 +11:00
rustc_errors Remove some low-value `use` renamings. 2024-05-03 16:03:12 +10:00
rustc_expand Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_feature Auto merge of #124747 - MasterAwesome:master, r=davidtwco 2024-05-06 00:55:49 +00:00
rustc_fluent_macro Rename `SubdiagnosticMessage` as `SubdiagMessage`. 2024-03-05 12:14:49 +11:00
rustc_fs_util Stabilize `std::path::absolute` 2024-04-24 14:35:02 +00:00
rustc_graphviz
rustc_hir Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillot 2024-05-04 00:32:27 +00:00
rustc_hir_analysis Auto merge of #124219 - gurry:122989-ice-unexpected-anon-const, r=compiler-errors 2024-05-07 20:01:18 +00:00
rustc_hir_pretty put `hir::AnonConst` on the hir arena 2024-04-26 12:57:02 +00:00
rustc_hir_typeck generalize hr alias: avoid unconstrainable infer vars 2024-05-07 15:58:06 +00:00
rustc_incremental Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk 2024-05-03 17:41:48 +00:00
rustc_index Simplify `static_assert_size`s. 2024-04-18 15:36:25 +10:00
rustc_index_macros rustc_index: Add a `ZERO` constant to index types 2024-04-03 19:06:22 +03:00
rustc_infer Rollup merge of #124827 - lcnr:generalize-incomplete, r=compiler-errors 2024-05-07 18:12:55 +02:00
rustc_interface Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
rustc_lexer Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
rustc_lint Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_lint_defs Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
rustc_llvm Rollup merge of #124287 - 41Leahcim:master, r=fmease 2024-04-25 18:57:56 +02:00
rustc_log Construct `SourceMap` at the same time as `SessionGlobals`. 2024-04-16 13:02:53 +10:00
rustc_macros Rollup merge of #124287 - 41Leahcim:master, r=fmease 2024-04-25 18:57:56 +02:00
rustc_metadata Rollup merge of #124582 - RalfJung:std-not-found, r=Nilstrieb 2024-05-02 15:11:22 +02:00
rustc_middle Rollup merge of #124548 - gurry:113272-ice-failed-to-normalize, r=compiler-errors 2024-05-08 17:03:08 +02:00
rustc_mir_build Auto merge of #124223 - Zalathar:conditional-let, r=compiler-errors 2024-05-07 22:28:51 +00:00
rustc_mir_dataflow Inline & delete `Ty::new_unit`, since it's just a field access 2024-05-02 17:49:23 +02:00
rustc_mir_transform coverage: Rename `BcbBranchPair` to `mappings::BranchPair` 2024-05-04 11:26:05 +10:00
rustc_monomorphize Remove `extern crate rustc_middle` from numerous crates. 2024-04-29 14:50:45 +10:00
rustc_next_trait_solver Use super_fold in RegionsToStatic visitor 2024-05-06 12:22:15 -04:00
rustc_parse Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_parse_format Simplify `static_assert_size`s. 2024-04-18 15:36:25 +10:00
rustc_passes Various improvements to entrypoint code 2024-05-04 14:48:42 +02:00
rustc_pattern_analysis Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
rustc_privacy Remove some unneeded `Cargo.toml` dependencies. 2024-05-03 15:33:52 +10:00
rustc_query_impl Stabilize generic `NonZero`. 2024-04-22 18:48:47 +02:00
rustc_query_system Remove some unneeded `Cargo.toml` dependencies. 2024-05-03 15:33:52 +10:00
rustc_resolve Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb 2024-05-08 23:33:24 +02:00
rustc_sanitizers Stabilize the size of incr comp object file names 2024-04-22 10:50:07 -04:00
rustc_serialize Step bootstrap cfgs 2024-05-01 22:19:11 -04:00
rustc_session Add `rustfmt` cfg to well known cfgs list 2024-05-05 14:30:35 +02:00
rustc_smir Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasper 2024-04-23 17:25:15 +02:00
rustc_span Auto merge of #124747 - MasterAwesome:master, r=davidtwco 2024-05-06 00:55:49 +00:00
rustc_symbol_mangling Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk 2024-05-03 17:41:48 +00:00
rustc_target Auto merge of #124858 - alexcrichton:some-wasi-changes, r=michaelwoerister 2024-05-08 11:39:26 +00:00
rustc_trait_selection Auto merge of #124683 - estebank:issue-124651, r=compiler-errors 2024-05-08 00:54:38 +00:00
rustc_traits Use ObligationCtxt in favor of TraitEngine in many places 2024-05-02 22:03:01 -04:00
rustc_transmute Align: add bytes_usize and bits_usize 2024-05-01 15:57:33 +02:00
rustc_ty_utils Inline & delete `Ty::new_unit`, since it's just a field access 2024-05-02 17:49:23 +02:00
rustc_type_ir Remove `extern crate bitflags` from a couple of crates. 2024-04-29 18:47:54 +10:00
stable_mir Remove `extern crate scoped_tls` from `stable_mir`. 2024-04-30 16:47:49 +10:00