Skip to content

Commit d834d2a

Browse files
committed
Silence confusing 'unused import' warnings.
1 parent ce95a57 commit d834d2a

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ impl<'a> Resolver<'a> {
986986
import.span,
987987
&format!("`{}` is imported here, but {}", ident, it_is),
988988
);
989+
// Silence the 'unused import' warning we might get,
990+
// since this diagnostic already covers that import.
991+
self.record_use(ident, binding, false);
989992
return;
990993
}
991994
}

src/test/ui/macros/issue-88206.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// compile-flags: -Z deduplicate-diagnostics=yes
22

33
#![warn(unused_imports)]
4-
//~^ NOTE lint level
54

65
use std::str::*;
7-
//~^ WARNING unused import
8-
//~| NOTE `from_utf8` is imported here, but it is not a macro
6+
//~^ NOTE `from_utf8` is imported here, but it is not a macro
97
//~| NOTE `from_utf8_mut` is imported here, but it is not a derive macro
108
//~| NOTE `from_utf8_unchecked` is imported here, but it is not an attribute
119

@@ -15,8 +13,7 @@ mod hey {
1513
}
1614

1715
use hey::{Serialize, Deserialize};
18-
//~^ WARNING unused import
19-
//~| NOTE `Serialize` is imported here, but it is not a derive macro
16+
//~^ NOTE `Serialize` is imported here, but it is not a derive macro
2017
//~| NOTE `Deserialize` is imported here, but it is not an attribute
2118

2219
#[derive(Serialize)]

src/test/ui/macros/issue-88206.stderr

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,102 @@
11
error: cannot find macro `test` in this scope
2-
--> $DIR/issue-88206.rs:60:5
2+
--> $DIR/issue-88206.rs:57:5
33
|
44
LL | test!();
55
| ^^^^
66
|
77
= note: `test` is in scope, but it is an attribute
88

99
error: cannot find macro `Copy` in this scope
10-
--> $DIR/issue-88206.rs:56:5
10+
--> $DIR/issue-88206.rs:53:5
1111
|
1212
LL | Copy!();
1313
| ^^^^
1414
|
1515
= note: `Copy` is in scope, but it is a derive macro
1616

1717
error: cannot find macro `Box` in this scope
18-
--> $DIR/issue-88206.rs:52:5
18+
--> $DIR/issue-88206.rs:49:5
1919
|
2020
LL | Box!();
2121
| ^^^
2222
|
2323
= note: `Box` is in scope, but it is not a macro
2424

2525
error: cannot find macro `from_utf8` in this scope
26-
--> $DIR/issue-88206.rs:49:5
26+
--> $DIR/issue-88206.rs:46:5
2727
|
2828
LL | from_utf8!();
2929
| ^^^^^^^^^
3030
|
3131
note: `from_utf8` is imported here, but it is not a macro
32-
--> $DIR/issue-88206.rs:6:5
32+
--> $DIR/issue-88206.rs:5:5
3333
|
3434
LL | use std::str::*;
3535
| ^^^^^^^^^^^
3636

3737
error: cannot find attribute `println` in this scope
38-
--> $DIR/issue-88206.rs:43:3
38+
--> $DIR/issue-88206.rs:40:3
3939
|
4040
LL | #[println]
4141
| ^^^^^^^
4242
|
4343
= note: `println` is in scope, but it is a function-like macro
4444

4545
error: cannot find attribute `from_utf8_unchecked` in this scope
46-
--> $DIR/issue-88206.rs:39:3
46+
--> $DIR/issue-88206.rs:36:3
4747
|
4848
LL | #[from_utf8_unchecked]
4949
| ^^^^^^^^^^^^^^^^^^^
5050
|
5151
note: `from_utf8_unchecked` is imported here, but it is not an attribute
52-
--> $DIR/issue-88206.rs:6:5
52+
--> $DIR/issue-88206.rs:5:5
5353
|
5454
LL | use std::str::*;
5555
| ^^^^^^^^^^^
5656

5757
error: cannot find attribute `Deserialize` in this scope
58-
--> $DIR/issue-88206.rs:35:3
58+
--> $DIR/issue-88206.rs:32:3
5959
|
6060
LL | #[Deserialize]
6161
| ^^^^^^^^^^^
6262
|
6363
note: `Deserialize` is imported here, but it is not an attribute
64-
--> $DIR/issue-88206.rs:17:22
64+
--> $DIR/issue-88206.rs:15:22
6565
|
6666
LL | use hey::{Serialize, Deserialize};
6767
| ^^^^^^^^^^^
6868

6969
error: cannot find derive macro `println` in this scope
70-
--> $DIR/issue-88206.rs:30:10
70+
--> $DIR/issue-88206.rs:27:10
7171
|
7272
LL | #[derive(println)]
7373
| ^^^^^^^
7474
|
7575
= note: `println` is in scope, but it is a function-like macro
7676

7777
error: cannot find derive macro `from_utf8_mut` in this scope
78-
--> $DIR/issue-88206.rs:26:10
78+
--> $DIR/issue-88206.rs:23:10
7979
|
8080
LL | #[derive(from_utf8_mut)]
8181
| ^^^^^^^^^^^^^
8282
|
8383
note: `from_utf8_mut` is imported here, but it is not a derive macro
84-
--> $DIR/issue-88206.rs:6:5
84+
--> $DIR/issue-88206.rs:5:5
8585
|
8686
LL | use std::str::*;
8787
| ^^^^^^^^^^^
8888

8989
error: cannot find derive macro `Serialize` in this scope
90-
--> $DIR/issue-88206.rs:22:10
90+
--> $DIR/issue-88206.rs:19:10
9191
|
9292
LL | #[derive(Serialize)]
9393
| ^^^^^^^^^
9494
|
9595
note: `Serialize` is imported here, but it is not a derive macro
96-
--> $DIR/issue-88206.rs:17:11
96+
--> $DIR/issue-88206.rs:15:11
9797
|
9898
LL | use hey::{Serialize, Deserialize};
9999
| ^^^^^^^^^
100100

101-
warning: unused import: `std::str::*`
102-
--> $DIR/issue-88206.rs:6:5
103-
|
104-
LL | use std::str::*;
105-
| ^^^^^^^^^^^
106-
|
107-
note: the lint level is defined here
108-
--> $DIR/issue-88206.rs:3:9
109-
|
110-
LL | #![warn(unused_imports)]
111-
| ^^^^^^^^^^^^^^
112-
113-
warning: unused imports: `Deserialize`, `Serialize`
114-
--> $DIR/issue-88206.rs:17:11
115-
|
116-
LL | use hey::{Serialize, Deserialize};
117-
| ^^^^^^^^^ ^^^^^^^^^^^
118-
119-
error: aborting due to 10 previous errors; 2 warnings emitted
101+
error: aborting due to 10 previous errors
120102

0 commit comments

Comments
 (0)