Improve wording of macro-not-found-but-name-exists note.

This commit is contained in:
Mara Bos 2021-08-22 18:22:06 +02:00
parent 4e22bf47d0
commit 908ce2fd1f
3 changed files with 20 additions and 10 deletions

View File

@ -971,14 +971,24 @@ fn lookup_import_candidates_from_module<FilterFn>(
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(),

View File

@ -15,7 +15,7 @@ pub trait Deserialize {}
}
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

View File

@ -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};