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

View File

@ -3,18 +3,21 @@
#![warn(unused_imports)] #![warn(unused_imports)]
use std::str::*; use std::str::*;
//~^ NOTE `from_utf8` is imported here, but it is not a macro //~^ NOTE `from_utf8` is imported here, but it is a function
//~| 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
//~| 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
mod hey { mod hey {
pub trait Serialize {} pub trait Serialize {}
pub trait Deserialize {} pub trait Deserialize {}
pub struct X(i32);
} }
use hey::{Serialize, Deserialize}; use hey::{Serialize, Deserialize, X};
//~^ NOTE `Serialize` is imported here, but it is not a derive macro //~^ NOTE `Serialize` is imported here, but it is a trait
//~| NOTE `Deserialize` is imported here, but it is not an attribute //~| NOTE `Deserialize` is imported here, but it is a trait
//~| NOTE `X` is imported here, but it is a struct
#[derive(Serialize)] #[derive(Serialize)]
//~^ ERROR cannot find derive macro `Serialize` //~^ ERROR cannot find derive macro `Serialize`
@ -48,7 +51,7 @@ fn main() {
Box!(); Box!();
//~^ ERROR cannot find macro `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!(); Copy!();
//~^ ERROR cannot find macro `Copy` //~^ ERROR cannot find macro `Copy`
@ -57,4 +60,7 @@ fn main() {
test!(); test!();
//~^ ERROR cannot find macro `test` //~^ ERROR cannot find macro `test`
//~| NOTE `test` is in scope, but it is an attribute //~| 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 error: cannot find macro `test` in this scope
--> $DIR/issue-88206.rs:57:5 --> $DIR/issue-88206.rs:60:5
| |
LL | test!(); LL | test!();
| ^^^^ | ^^^^
@ -7,7 +19,7 @@ LL | test!();
= note: `test` is in scope, but it is an attribute = note: `test` is in scope, but it is an attribute
error: cannot find macro `Copy` in this scope error: cannot find macro `Copy` in this scope
--> $DIR/issue-88206.rs:53:5 --> $DIR/issue-88206.rs:56:5
| |
LL | Copy!(); LL | Copy!();
| ^^^^ | ^^^^
@ -15,27 +27,27 @@ LL | Copy!();
= note: `Copy` is in scope, but it is a derive macro = note: `Copy` is in scope, but it is a derive macro
error: cannot find macro `Box` in this scope error: cannot find macro `Box` in this scope
--> $DIR/issue-88206.rs:49:5 --> $DIR/issue-88206.rs:52:5
| |
LL | Box!(); 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 error: cannot find macro `from_utf8` in this scope
--> $DIR/issue-88206.rs:46:5 --> $DIR/issue-88206.rs:49:5
| |
LL | from_utf8!(); 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 --> $DIR/issue-88206.rs:5:5
| |
LL | use std::str::*; LL | use std::str::*;
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: cannot find attribute `println` in this scope error: cannot find attribute `println` in this scope
--> $DIR/issue-88206.rs:40:3 --> $DIR/issue-88206.rs:43:3
| |
LL | #[println] LL | #[println]
| ^^^^^^^ | ^^^^^^^
@ -43,31 +55,31 @@ LL | #[println]
= note: `println` is in scope, but it is a function-like macro = note: `println` is in scope, but it is a function-like macro
error: cannot find attribute `from_utf8_unchecked` in this scope 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] 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 --> $DIR/issue-88206.rs:5:5
| |
LL | use std::str::*; LL | use std::str::*;
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: cannot find attribute `Deserialize` in this scope error: cannot find attribute `Deserialize` in this scope
--> $DIR/issue-88206.rs:32:3 --> $DIR/issue-88206.rs:35:3
| |
LL | #[Deserialize] LL | #[Deserialize]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
note: `Deserialize` is imported here, but it is not an attribute note: `Deserialize` is imported here, but it is a trait
--> $DIR/issue-88206.rs:15:22 --> $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 error: cannot find derive macro `println` in this scope
--> $DIR/issue-88206.rs:27:10 --> $DIR/issue-88206.rs:30:10
| |
LL | #[derive(println)] LL | #[derive(println)]
| ^^^^^^^ | ^^^^^^^
@ -75,28 +87,28 @@ LL | #[derive(println)]
= note: `println` is in scope, but it is a function-like macro = note: `println` is in scope, but it is a function-like macro
error: cannot find derive macro `from_utf8_mut` in this scope 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)] 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 --> $DIR/issue-88206.rs:5:5
| |
LL | use std::str::*; LL | use std::str::*;
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: cannot find derive macro `Serialize` in this scope error: cannot find derive macro `Serialize` in this scope
--> $DIR/issue-88206.rs:19:10 --> $DIR/issue-88206.rs:22:10
| |
LL | #[derive(Serialize)] LL | #[derive(Serialize)]
| ^^^^^^^^^ | ^^^^^^^^^
| |
note: `Serialize` is imported here, but it is not a derive macro note: `Serialize` is imported here, but it is a trait
--> $DIR/issue-88206.rs:15:11 --> $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)] 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 error: cannot find derive macro `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:4:10 --> $DIR/tool-attributes-misplaced-1.rs:4:10
@ -12,7 +12,7 @@ error: cannot find derive macro `rustfmt` in this scope
LL | #[derive(rustfmt)] 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 error: cannot find attribute `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:9:3 --> $DIR/tool-attributes-misplaced-1.rs:9:3
@ -20,7 +20,7 @@ error: cannot find attribute `rustfmt` in this scope
LL | #[rustfmt] 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 error: cannot find macro `rustfmt` in this scope
--> $DIR/tool-attributes-misplaced-1.rs:15:5 --> $DIR/tool-attributes-misplaced-1.rs:15:5
@ -28,7 +28,7 @@ error: cannot find macro `rustfmt` in this scope
LL | rustfmt!(); 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` error[E0573]: expected type, found tool module `rustfmt`
--> $DIR/tool-attributes-misplaced-1.rs:1:10 --> $DIR/tool-attributes-misplaced-1.rs:1:10