Skip to content

Commit 3211f38

Browse files
committed
Tweak unnecessary import suggestion
1 parent 9bfb0ef commit 3211f38

9 files changed

+25
-45
lines changed

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4932,7 +4932,7 @@ impl<'a> Resolver<'a> {
49324932
Some((directive, _, true)) if should_remove_import && !directive.is_glob() => {
49334933
// Simple case - remove the entire import. Due to the above match arm, this can
49344934
// only be a single use so just remove it entirely.
4935-
err.span_suggestion(
4935+
err.span_suggestion_hidden(
49364936
directive.use_span_with_attributes,
49374937
"remove unnecessary import",
49384938
String::new(),

src/test/ui/double-type-import.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `X` is defined multiple times
44
LL | pub use self::bar::X;
55
| ------------ previous import of the type `X` here
66
LL | use self::bar::X;
7-
| ----^^^^^^^^^^^^-
8-
| | |
9-
| | `X` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^^^^^^^ `X` reimported here
118
|
129
= note: `X` must be defined only once in the type namespace of this module
10+
= help: remove unnecessary import
1311

1412
error: aborting due to previous error
1513

src/test/ui/imports/duplicate.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `foo` is defined multiple times
44
LL | use a::foo;
55
| ------ previous import of the value `foo` here
66
LL | use a::foo;
7-
| ----^^^^^^-
8-
| | |
9-
| | `foo` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^ `foo` reimported here
118
|
129
= note: `foo` must be defined only once in the value namespace of this module
10+
= help: remove unnecessary import
1311

1412
error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
1513
--> $DIR/duplicate.rs:46:15

src/test/ui/issues/issue-26886.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `Arc` is defined multiple times
44
LL | use std::sync::{self, Arc};
55
| --- previous import of the type `Arc` here
66
LL | use std::sync::Arc;
7-
| ----^^^^^^^^^^^^^^-
8-
| | |
9-
| | `Arc` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^^^^^^^^^ `Arc` reimported here
118
|
129
= note: `Arc` must be defined only once in the type namespace of this module
10+
= help: remove unnecessary import
1311

1412
error[E0252]: the name `sync` is defined multiple times
1513
--> $DIR/issue-26886.rs:4:5
@@ -18,12 +16,10 @@ LL | use std::sync::{self, Arc};
1816
| ---- previous import of the module `sync` here
1917
...
2018
LL | use std::sync;
21-
| ----^^^^^^^^^-
22-
| | |
23-
| | `sync` reimported here
24-
| help: remove unnecessary import
19+
| ^^^^^^^^^ `sync` reimported here
2520
|
2621
= note: `sync` must be defined only once in the type namespace of this module
22+
= help: remove unnecessary import
2723

2824
error: aborting due to 2 previous errors
2925

src/test/ui/issues/issue-52891.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `a` is defined multiple times
44
LL | use issue_52891::a;
55
| -------------- previous import of the module `a` here
66
LL | use issue_52891::a;
7-
| ----^^^^^^^^^^^^^^-
8-
| | |
9-
| | `a` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^^^^^^^^^ `a` reimported here
118
|
129
= note: `a` must be defined only once in the type namespace of this module
10+
= help: remove unnecessary import
1311

1412
error[E0252]: the name `a` is defined multiple times
1513
--> $DIR/issue-52891.rs:14:19
@@ -129,15 +127,13 @@ error[E0252]: the name `n` is defined multiple times
129127
--> $DIR/issue-52891.rs:36:5
130128
|
131129
LL | use issue_52891::n;
132-
| -------------------
133-
| | |
134-
| | previous import of the module `n` here
135-
| help: remove unnecessary import
130+
| -------------- previous import of the module `n` here
136131
LL | #[macro_use]
137132
LL | use issue_52891::n;
138133
| ^^^^^^^^^^^^^^ `n` reimported here
139134
|
140135
= note: `n` must be defined only once in the type namespace of this module
136+
= help: remove unnecessary import
141137

142138
error: aborting due to 10 previous errors
143139

src/test/ui/proc-macro/shadow.stderr

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
error[E0259]: the name `derive_a` is defined multiple times
22
--> $DIR/shadow.rs:6:1
33
|
4-
LL | extern crate derive_a;
5-
| ---------------------- previous import of the extern crate `derive_a` here
6-
LL | / #[macro_use]
7-
LL | | extern crate derive_a;
8-
| | ^^^^^^^^^^^^^^^^^^^^^-
9-
| |_|____________________|
10-
| | help: remove unnecessary import
11-
| `derive_a` reimported here
4+
LL | extern crate derive_a;
5+
| ---------------------- previous import of the extern crate `derive_a` here
6+
LL | #[macro_use]
7+
LL | extern crate derive_a;
8+
| ^^^^^^^^^^^^^^^^^^^^^^ `derive_a` reimported here
129
|
1310
= note: `derive_a` must be defined only once in the type namespace of this module
11+
= help: remove unnecessary import
1412

1513
error: aborting due to previous error
1614

src/test/ui/resolve/resolve-conflict-import-vs-import.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `transmute` is defined multiple times
44
LL | use std::mem::transmute;
55
| ------------------- previous import of the value `transmute` here
66
LL | use std::mem::transmute;
7-
| ----^^^^^^^^^^^^^^^^^^^-
8-
| | |
9-
| | `transmute` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^^^^^^^^^^^^^^ `transmute` reimported here
118
|
129
= note: `transmute` must be defined only once in the value namespace of this module
10+
= help: remove unnecessary import
1311

1412
error: aborting due to previous error
1513

src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0254]: the name `core` is defined multiple times
44
LL | extern crate core;
55
| ------------------ previous import of the extern crate `core` here
66
LL | use core;
7-
| ----^^^^-
8-
| | |
9-
| | `core` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^ `core` reimported here
118
|
129
= note: `core` must be defined only once in the type namespace of this module
10+
= help: remove unnecessary import
1311

1412
error: aborting due to previous error
1513

src/test/ui/use/use-paths-as-items.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ error[E0252]: the name `mem` is defined multiple times
44
LL | use std::{mem, ptr};
55
| --- previous import of the module `mem` here
66
LL | use std::mem;
7-
| ----^^^^^^^^-
8-
| | |
9-
| | `mem` reimported here
10-
| help: remove unnecessary import
7+
| ^^^^^^^^ `mem` reimported here
118
|
129
= note: `mem` must be defined only once in the type namespace of this module
10+
= help: remove unnecessary import
1311

1412
error: aborting due to previous error
1513

0 commit comments

Comments
 (0)