Say what things are, instead of what they are not.

This commit is contained in:
Mara Bos 2021-08-22 17:16:24 +02:00
parent d834d2a742
commit 5dea5d7549
4 changed files with 59 additions and 42 deletions

View File

@ -971,20 +971,19 @@ impl<'a> Resolver<'a> {
false,
ident.span,
) {
let it_is = match binding.macro_kind() {
Some(MacroKind::Bang) => "it is a function-like macro".to_string(),
Some(kind) => format!("it is {} {}", kind.article(), kind.descr_expected()),
None => format!(
"it is not {} {}",
macro_kind.article(),
macro_kind.descr_expected()
),
let desc = match binding.macro_kind() {
Some(MacroKind::Bang) => "a function-like macro".to_string(),
Some(kind) => format!("{} {}", kind.article(), kind.descr_expected()),
None => {
let res = binding.res();
format!("{} {}", res.article(), res.descr())
}
};
if let crate::NameBindingKind::Import { import, .. } = binding.kind {
if !import.span.is_dummy() {
err.span_note(
import.span,
&format!("`{}` is imported here, but {}", ident, it_is),
&format!("`{}` is imported here, but it is {}", ident, desc),
);
// Silence the 'unused import' warning we might get,
// since this diagnostic already covers that import.
@ -992,7 +991,7 @@ impl<'a> Resolver<'a> {
return;
}
}
err.note(&format!("`{}` is in scope, but {}", ident, it_is));
err.note(&format!("`{}` is in scope, but it is {}", ident, desc));
return;
}
}

View File

@ -3,18 +3,21 @@
#![warn(unused_imports)]
use std::str::*;
//~^ NOTE `from_utf8` is imported here, but it is not a macro
//~| NOTE `from_utf8_mut` is imported here, but it is not a derive macro
//~| NOTE `from_utf8_unchecked` is imported here, but it is not an attribute
//~^ NOTE `from_utf8` is imported here, but it is a function
//~| NOTE `from_utf8_mut` is imported here, but it is a function
//~| NOTE `from_utf8_unchecked` is imported here, but it is a function
mod hey {
pub trait Serialize {}
pub trait Deserialize {}
pub struct X(i32);
}
use hey::{Serialize, Deserialize};
//~^ NOTE `Serialize` is imported here, but it is not a derive macro
//~| NOTE `Deserialize` is imported here, but it is not an attribute
use hey::{Serialize, Deserialize, X};
//~^ NOTE `Serialize` is imported here, but it is a trait
//~| NOTE `Deserialize` is imported here, but it is a trait
//~| NOTE `X` is imported here, but it is a struct
#[derive(Serialize)]
//~^ ERROR cannot find derive macro `Serialize`
@ -48,7 +51,7 @@ fn main() {
Box!();
//~^ ERROR cannot find macro `Box`
//~| NOTE `Box` is in scope, but it is not a macro
//~| NOTE `Box` is in scope, but it is a struct
Copy!();
//~^ ERROR cannot find macro `Copy`
@ -57,4 +60,7 @@ fn main() {
test!();
//~^ ERROR cannot find macro `test`
//~| NOTE `test` is in scope, but it is an attribute
X!();
//~^ ERROR cannot find macro `X`
}

View File

@ -1,5 +1,17 @@
error: cannot find macro `X` in this scope
--> $DIR/issue-88206.rs:64:5
|
LL | X!();
| ^
|
note: `X` is imported here, but it is a struct
--> $DIR/issue-88206.rs:17:35
|
LL | use hey::{Serialize, Deserialize, X};
| ^
error: cannot find macro `test` in this scope
--> $DIR/issue-88206.rs:57:5
--> $DIR/issue-88206.rs:60:5
|
LL | test!();
| ^^^^
@ -7,7 +19,7 @@ LL | test!();
= note: `test` is in scope, but it is an attribute
error: cannot find macro `Copy` in this scope
--> $DIR/issue-88206.rs:53:5
--> $DIR/issue-88206.rs:56:5
|
LL | Copy!();
| ^^^^
@ -15,27 +27,27 @@ LL | Copy!();
= note: `Copy` is in scope, but it is a derive macro
error: cannot find macro `Box` in this scope
--> $DIR/issue-88206.rs:49:5
--> $DIR/issue-88206.rs:52:5
|
LL | Box!();
| ^^^
|
= note: `Box` is in scope, but it is not a macro
= note: `Box` is in scope, but it is a struct
error: cannot find macro `from_utf8` in this scope
--> $DIR/issue-88206.rs:46:5
--> $DIR/issue-88206.rs:49:5
|
LL | from_utf8!();
| ^^^^^^^^^
|
note: `from_utf8` is imported here, but it is not a macro
note: `from_utf8` is imported here, but it is a function
--> $DIR/issue-88206.rs:5:5
|
LL | use std::str::*;
| ^^^^^^^^^^^
error: cannot find attribute `println` in this scope
--> $DIR/issue-88206.rs:40:3
--> $DIR/issue-88206.rs:43:3
|
LL | #[println]
| ^^^^^^^
@ -43,31 +55,31 @@ LL | #[println]
= note: `println` is in scope, but it is a function-like macro
error: cannot find attribute `from_utf8_unchecked` in this scope
--> $DIR/issue-88206.rs:36:3
--> $DIR/issue-88206.rs:39:3
|
LL | #[from_utf8_unchecked]
| ^^^^^^^^^^^^^^^^^^^
|
note: `from_utf8_unchecked` is imported here, but it is not an attribute
note: `from_utf8_unchecked` is imported here, but it is a function
--> $DIR/issue-88206.rs:5:5
|
LL | use std::str::*;
| ^^^^^^^^^^^
error: cannot find attribute `Deserialize` in this scope
--> $DIR/issue-88206.rs:32:3
--> $DIR/issue-88206.rs:35:3
|
LL | #[Deserialize]
| ^^^^^^^^^^^
|
note: `Deserialize` is imported here, but it is not an attribute
--> $DIR/issue-88206.rs:15:22
note: `Deserialize` is imported here, but it is a trait
--> $DIR/issue-88206.rs:17:22
|
LL | use hey::{Serialize, Deserialize};
LL | use hey::{Serialize, Deserialize, X};
| ^^^^^^^^^^^
error: cannot find derive macro `println` in this scope
--> $DIR/issue-88206.rs:27:10
--> $DIR/issue-88206.rs:30:10
|
LL | #[derive(println)]
| ^^^^^^^
@ -75,28 +87,28 @@ LL | #[derive(println)]
= note: `println` is in scope, but it is a function-like macro
error: cannot find derive macro `from_utf8_mut` in this scope
--> $DIR/issue-88206.rs:23:10
--> $DIR/issue-88206.rs:26:10
|
LL | #[derive(from_utf8_mut)]
| ^^^^^^^^^^^^^
|
note: `from_utf8_mut` is imported here, but it is not a derive macro
note: `from_utf8_mut` is imported here, but it is a function
--> $DIR/issue-88206.rs:5:5
|
LL | use std::str::*;
| ^^^^^^^^^^^
error: cannot find derive macro `Serialize` in this scope
--> $DIR/issue-88206.rs:19:10
--> $DIR/issue-88206.rs:22:10
|
LL | #[derive(Serialize)]
| ^^^^^^^^^
|
note: `Serialize` is imported here, but it is not a derive macro
--> $DIR/issue-88206.rs:15:11
note: `Serialize` is imported here, but it is a trait
--> $DIR/issue-88206.rs:17:11
|
LL | use hey::{Serialize, Deserialize};
LL | use hey::{Serialize, Deserialize, X};
| ^^^^^^^^^
error: aborting due to 10 previous errors
error: aborting due to 11 previous errors

View File

@ -4,7 +4,7 @@ error: cannot find derive macro `rustfmt` in this scope
LL | #[derive(rustfmt)]
| ^^^^^^^
|
= note: `rustfmt` is in scope, but it is not a derive macro
= note: `rustfmt` is in scope, but it is a tool module
error: cannot find derive macro `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:4:10
@ -12,7 +12,7 @@ error: cannot find derive macro `rustfmt` in this scope
LL | #[derive(rustfmt)]
| ^^^^^^^
|
= note: `rustfmt` is in scope, but it is not a derive macro
= note: `rustfmt` is in scope, but it is a tool module
error: cannot find attribute `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:9:3
@ -20,7 +20,7 @@ error: cannot find attribute `rustfmt` in this scope
LL | #[rustfmt]
| ^^^^^^^
|
= note: `rustfmt` is in scope, but it is not an attribute
= note: `rustfmt` is in scope, but it is a tool module
error: cannot find macro `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:15:5
@ -28,7 +28,7 @@ error: cannot find macro `rustfmt` in this scope
LL | rustfmt!();
| ^^^^^^^
|
= note: `rustfmt` is in scope, but it is not a macro
= note: `rustfmt` is in scope, but it is a tool module
error[E0573]: expected type, found tool module `rustfmt`
--> $DIR/tool-attributes-misplaced-1.rs:1:10