From 908ce2fd1f8f87a18f005b6d86276649786475d8 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 22 Aug 2021 18:22:06 +0200 Subject: [PATCH] Improve wording of macro-not-found-but-name-exists note. --- compiler/rustc_resolve/src/diagnostics.rs | 26 ++++++++++++++++------- src/test/ui/macros/issue-88206.rs | 2 +- src/test/ui/macros/issue-88206.stderr | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a6e26d06bb12a..ca2c22854c4f5 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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(), diff --git a/src/test/ui/macros/issue-88206.rs b/src/test/ui/macros/issue-88206.rs index 9f1306349e901..14e2f66068b01 100644 --- a/src/test/ui/macros/issue-88206.rs +++ b/src/test/ui/macros/issue-88206.rs @@ -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 diff --git a/src/test/ui/macros/issue-88206.stderr b/src/test/ui/macros/issue-88206.stderr index 0413605fdb7f2..f7f5b56488007 100644 --- a/src/test/ui/macros/issue-88206.stderr +++ b/src/test/ui/macros/issue-88206.stderr @@ -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};