Skip to content

Commit 908ce2f

Browse files
committed
Improve wording of macro-not-found-but-name-exists note.
1 parent 4e22bf4 commit 908ce2f

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,24 @@ impl<'a> Resolver<'a> {
971971
false,
972972
ident.span,
973973
) {
974-
let res = binding.res();
975-
let desc = match res.macro_kind() {
976-
Some(MacroKind::Bang) => "a function-like macro".to_string(),
977-
Some(MacroKind::Attr) => format!("an attribute: `#[{}]`", ident),
978-
Some(MacroKind::Derive) => format!("a derive macro: `#[derive({})]`", ident),
979-
// Don't confuse the user with tool modules.
980-
None if res == Res::ToolMod => continue,
981-
None => format!(
974+
let desc = match binding.res() {
975+
Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
976+
"a function-like macro".to_string()
977+
}
978+
Res::Def(DefKind::Macro(MacroKind::Attr), _) | Res::NonMacroAttr(..) => {
979+
format!("an attribute: `#[{}]`", ident)
980+
}
981+
Res::Def(DefKind::Macro(MacroKind::Derive), _) => {
982+
format!("a derive macro: `#[derive({})]`", ident)
983+
}
984+
Res::ToolMod => {
985+
// Don't confuse the user with tool modules.
986+
continue;
987+
}
988+
Res::Def(DefKind::Trait, _) if macro_kind == MacroKind::Derive => {
989+
"only a trait, without a derive macro".to_string()
990+
}
991+
res => format!(
982992
"{} {}, not {} {}",
983993
res.article(),
984994
res.descr(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod hey {
1515
}
1616

1717
use hey::{Serialize, Deserialize, X};
18-
//~^ NOTE `Serialize` is imported here, but it is a trait
18+
//~^ NOTE `Serialize` is imported here, but it is only a trait, without a derive macro
1919
//~| NOTE `Deserialize` is imported here, but it is a trait
2020
//~| NOTE `X` is imported here, but it is a struct
2121

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ error: cannot find derive macro `Serialize` in this scope
104104
LL | #[derive(Serialize)]
105105
| ^^^^^^^^^
106106
|
107-
note: `Serialize` is imported here, but it is a trait, not a derive macro
107+
note: `Serialize` is imported here, but it is only a trait, without a derive macro
108108
--> $DIR/issue-88206.rs:17:11
109109
|
110110
LL | use hey::{Serialize, Deserialize, X};

0 commit comments

Comments
 (0)