Skip to content

Commit

Permalink
Improve wording of macro-not-found-but-name-exists note.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Aug 23, 2021
1 parent 4e22bf4 commit 908ce2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,24 @@ impl<'a> Resolver<'a> {
false,
ident.span,
) {
let res = binding.res();
let desc = match res.macro_kind() {
Some(MacroKind::Bang) => "a function-like macro".to_string(),
Some(MacroKind::Attr) => format!("an attribute: `#[{}]`", ident),
Some(MacroKind::Derive) => format!("a derive macro: `#[derive({})]`", ident),
// Don't confuse the user with tool modules.
None if res == Res::ToolMod => continue,
None => format!(
let desc = match binding.res() {
Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
"a function-like macro".to_string()
}
Res::Def(DefKind::Macro(MacroKind::Attr), _) | Res::NonMacroAttr(..) => {
format!("an attribute: `#[{}]`", ident)
}
Res::Def(DefKind::Macro(MacroKind::Derive), _) => {
format!("a derive macro: `#[derive({})]`", ident)
}
Res::ToolMod => {
// Don't confuse the user with tool modules.
continue;
}
Res::Def(DefKind::Trait, _) if macro_kind == MacroKind::Derive => {
"only a trait, without a derive macro".to_string()
}
res => format!(
"{} {}, not {} {}",
res.article(),
res.descr(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/issue-88206.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod hey {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/issue-88206.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ error: cannot find derive macro `Serialize` in this scope
LL | #[derive(Serialize)]
| ^^^^^^^^^
|
note: `Serialize` is imported here, but it is a trait, not a derive macro
note: `Serialize` is imported here, but it is only a trait, without a derive macro
--> $DIR/issue-88206.rs:17:11
|
LL | use hey::{Serialize, Deserialize, X};
Expand Down

0 comments on commit 908ce2f

Please sign in to comment.