Skip to content

Commit 5dea5d7

Browse files
committed
Say what things are, instead of what they are not.
1 parent d834d2a commit 5dea5d7

File tree

4 files changed

+59
-42
lines changed

4 files changed

+59
-42
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -971,28 +971,27 @@ impl<'a> Resolver<'a> {
971971
false,
972972
ident.span,
973973
) {
974-
let it_is = match binding.macro_kind() {
975-
Some(MacroKind::Bang) => "it is a function-like macro".to_string(),
976-
Some(kind) => format!("it is {} {}", kind.article(), kind.descr_expected()),
977-
None => format!(
978-
"it is not {} {}",
979-
macro_kind.article(),
980-
macro_kind.descr_expected()
981-
),
974+
let desc = match binding.macro_kind() {
975+
Some(MacroKind::Bang) => "a function-like macro".to_string(),
976+
Some(kind) => format!("{} {}", kind.article(), kind.descr_expected()),
977+
None => {
978+
let res = binding.res();
979+
format!("{} {}", res.article(), res.descr())
980+
}
982981
};
983982
if let crate::NameBindingKind::Import { import, .. } = binding.kind {
984983
if !import.span.is_dummy() {
985984
err.span_note(
986985
import.span,
987-
&format!("`{}` is imported here, but {}", ident, it_is),
986+
&format!("`{}` is imported here, but it is {}", ident, desc),
988987
);
989988
// Silence the 'unused import' warning we might get,
990989
// since this diagnostic already covers that import.
991990
self.record_use(ident, binding, false);
992991
return;
993992
}
994993
}
995-
err.note(&format!("`{}` is in scope, but {}", ident, it_is));
994+
err.note(&format!("`{}` is in scope, but it is {}", ident, desc));
996995
return;
997996
}
998997
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
#![warn(unused_imports)]
44

55
use std::str::*;
6-
//~^ NOTE `from_utf8` is imported here, but it is not a macro
7-
//~| NOTE `from_utf8_mut` is imported here, but it is not a derive macro
8-
//~| NOTE `from_utf8_unchecked` is imported here, but it is not an attribute
6+
//~^ NOTE `from_utf8` is imported here, but it is a function
7+
//~| NOTE `from_utf8_mut` is imported here, but it is a function
8+
//~| NOTE `from_utf8_unchecked` is imported here, but it is a function
99

1010
mod hey {
1111
pub trait Serialize {}
1212
pub trait Deserialize {}
13+
14+
pub struct X(i32);
1315
}
1416

15-
use hey::{Serialize, Deserialize};
16-
//~^ NOTE `Serialize` is imported here, but it is not a derive macro
17-
//~| NOTE `Deserialize` is imported here, but it is not an attribute
17+
use hey::{Serialize, Deserialize, X};
18+
//~^ NOTE `Serialize` is imported here, but it is a trait
19+
//~| NOTE `Deserialize` is imported here, but it is a trait
20+
//~| NOTE `X` is imported here, but it is a struct
1821

1922
#[derive(Serialize)]
2023
//~^ ERROR cannot find derive macro `Serialize`
@@ -48,7 +51,7 @@ fn main() {
4851

4952
Box!();
5053
//~^ ERROR cannot find macro `Box`
51-
//~| NOTE `Box` is in scope, but it is not a macro
54+
//~| NOTE `Box` is in scope, but it is a struct
5255

5356
Copy!();
5457
//~^ ERROR cannot find macro `Copy`
@@ -57,4 +60,7 @@ fn main() {
5760
test!();
5861
//~^ ERROR cannot find macro `test`
5962
//~| NOTE `test` is in scope, but it is an attribute
63+
64+
X!();
65+
//~^ ERROR cannot find macro `X`
6066
}

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,114 @@
1+
error: cannot find macro `X` in this scope
2+
--> $DIR/issue-88206.rs:64:5
3+
|
4+
LL | X!();
5+
| ^
6+
|
7+
note: `X` is imported here, but it is a struct
8+
--> $DIR/issue-88206.rs:17:35
9+
|
10+
LL | use hey::{Serialize, Deserialize, X};
11+
| ^
12+
113
error: cannot find macro `test` in this scope
2-
--> $DIR/issue-88206.rs:57:5
14+
--> $DIR/issue-88206.rs:60:5
315
|
416
LL | test!();
517
| ^^^^
618
|
719
= note: `test` is in scope, but it is an attribute
820

921
error: cannot find macro `Copy` in this scope
10-
--> $DIR/issue-88206.rs:53:5
22+
--> $DIR/issue-88206.rs:56:5
1123
|
1224
LL | Copy!();
1325
| ^^^^
1426
|
1527
= note: `Copy` is in scope, but it is a derive macro
1628

1729
error: cannot find macro `Box` in this scope
18-
--> $DIR/issue-88206.rs:49:5
30+
--> $DIR/issue-88206.rs:52:5
1931
|
2032
LL | Box!();
2133
| ^^^
2234
|
23-
= note: `Box` is in scope, but it is not a macro
35+
= note: `Box` is in scope, but it is a struct
2436

2537
error: cannot find macro `from_utf8` in this scope
26-
--> $DIR/issue-88206.rs:46:5
38+
--> $DIR/issue-88206.rs:49:5
2739
|
2840
LL | from_utf8!();
2941
| ^^^^^^^^^
3042
|
31-
note: `from_utf8` is imported here, but it is not a macro
43+
note: `from_utf8` is imported here, but it is a function
3244
--> $DIR/issue-88206.rs:5:5
3345
|
3446
LL | use std::str::*;
3547
| ^^^^^^^^^^^
3648

3749
error: cannot find attribute `println` in this scope
38-
--> $DIR/issue-88206.rs:40:3
50+
--> $DIR/issue-88206.rs:43:3
3951
|
4052
LL | #[println]
4153
| ^^^^^^^
4254
|
4355
= note: `println` is in scope, but it is a function-like macro
4456

4557
error: cannot find attribute `from_utf8_unchecked` in this scope
46-
--> $DIR/issue-88206.rs:36:3
58+
--> $DIR/issue-88206.rs:39:3
4759
|
4860
LL | #[from_utf8_unchecked]
4961
| ^^^^^^^^^^^^^^^^^^^
5062
|
51-
note: `from_utf8_unchecked` is imported here, but it is not an attribute
63+
note: `from_utf8_unchecked` is imported here, but it is a function
5264
--> $DIR/issue-88206.rs:5:5
5365
|
5466
LL | use std::str::*;
5567
| ^^^^^^^^^^^
5668

5769
error: cannot find attribute `Deserialize` in this scope
58-
--> $DIR/issue-88206.rs:32:3
70+
--> $DIR/issue-88206.rs:35:3
5971
|
6072
LL | #[Deserialize]
6173
| ^^^^^^^^^^^
6274
|
63-
note: `Deserialize` is imported here, but it is not an attribute
64-
--> $DIR/issue-88206.rs:15:22
75+
note: `Deserialize` is imported here, but it is a trait
76+
--> $DIR/issue-88206.rs:17:22
6577
|
66-
LL | use hey::{Serialize, Deserialize};
78+
LL | use hey::{Serialize, Deserialize, X};
6779
| ^^^^^^^^^^^
6880

6981
error: cannot find derive macro `println` in this scope
70-
--> $DIR/issue-88206.rs:27:10
82+
--> $DIR/issue-88206.rs:30:10
7183
|
7284
LL | #[derive(println)]
7385
| ^^^^^^^
7486
|
7587
= note: `println` is in scope, but it is a function-like macro
7688

7789
error: cannot find derive macro `from_utf8_mut` in this scope
78-
--> $DIR/issue-88206.rs:23:10
90+
--> $DIR/issue-88206.rs:26:10
7991
|
8092
LL | #[derive(from_utf8_mut)]
8193
| ^^^^^^^^^^^^^
8294
|
83-
note: `from_utf8_mut` is imported here, but it is not a derive macro
95+
note: `from_utf8_mut` is imported here, but it is a function
8496
--> $DIR/issue-88206.rs:5:5
8597
|
8698
LL | use std::str::*;
8799
| ^^^^^^^^^^^
88100

89101
error: cannot find derive macro `Serialize` in this scope
90-
--> $DIR/issue-88206.rs:19:10
102+
--> $DIR/issue-88206.rs:22:10
91103
|
92104
LL | #[derive(Serialize)]
93105
| ^^^^^^^^^
94106
|
95-
note: `Serialize` is imported here, but it is not a derive macro
96-
--> $DIR/issue-88206.rs:15:11
107+
note: `Serialize` is imported here, but it is a trait
108+
--> $DIR/issue-88206.rs:17:11
97109
|
98-
LL | use hey::{Serialize, Deserialize};
110+
LL | use hey::{Serialize, Deserialize, X};
99111
| ^^^^^^^^^
100112

101-
error: aborting due to 10 previous errors
113+
error: aborting due to 11 previous errors
102114

src/test/ui/tool-attributes/tool-attributes-misplaced-1.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ error: cannot find derive macro `rustfmt` in this scope
44
LL | #[derive(rustfmt)]
55
| ^^^^^^^
66
|
7-
= note: `rustfmt` is in scope, but it is not a derive macro
7+
= note: `rustfmt` is in scope, but it is a tool module
88

99
error: cannot find derive macro `rustfmt` in this scope
1010
--> $DIR/tool-attributes-misplaced-1.rs:4:10
1111
|
1212
LL | #[derive(rustfmt)]
1313
| ^^^^^^^
1414
|
15-
= note: `rustfmt` is in scope, but it is not a derive macro
15+
= note: `rustfmt` is in scope, but it is a tool module
1616

1717
error: cannot find attribute `rustfmt` in this scope
1818
--> $DIR/tool-attributes-misplaced-1.rs:9:3
1919
|
2020
LL | #[rustfmt]
2121
| ^^^^^^^
2222
|
23-
= note: `rustfmt` is in scope, but it is not an attribute
23+
= note: `rustfmt` is in scope, but it is a tool module
2424

2525
error: cannot find macro `rustfmt` in this scope
2626
--> $DIR/tool-attributes-misplaced-1.rs:15:5
2727
|
2828
LL | rustfmt!();
2929
| ^^^^^^^
3030
|
31-
= note: `rustfmt` is in scope, but it is not a macro
31+
= note: `rustfmt` is in scope, but it is a tool module
3232

3333
error[E0573]: expected type, found tool module `rustfmt`
3434
--> $DIR/tool-attributes-misplaced-1.rs:1:10

0 commit comments

Comments
 (0)