about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-08-22 18:22:06 +0200
committerMara Bos <m-ou.se@m-ou.se>2021-08-23 16:57:59 +0200
commit908ce2fd1f8f87a18f005b6d86276649786475d8 (patch)
tree58a1cd66889becdf6661de85b3750cb33ac3a971
parent4e22bf47d0fb496dea79ec436ad8f5f6fef2418c (diff)
downloadrust-908ce2fd1f8f87a18f005b6d86276649786475d8.tar.gz
rust-908ce2fd1f8f87a18f005b6d86276649786475d8.zip
Improve wording of macro-not-found-but-name-exists note.
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs26
-rw-r--r--src/test/ui/macros/issue-88206.rs2
-rw-r--r--src/test/ui/macros/issue-88206.stderr2
3 files changed, 20 insertions, 10 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index a6e26d06bb1..ca2c22854c4 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 9f1306349e9..14e2f66068b 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 0413605fdb7..f7f5b564880 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};