-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add notes to macro-not-found diagnostics to point out how things with the same name were not a match. #88232
Merged
bors
merged 11 commits into
rust-lang:master
from
m-ou-se:macro-name-imported-but-not-macro
Aug 23, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fed6131
Add note to 'macro not found' to point to identically-named imports.
m-ou-se 9051c05
Add test for macro-not-found-but-name-imported-here note.
m-ou-se 7977cb4
Look for macro names in all namespaces for diagnostics.
m-ou-se 11c879d
Add tests for macro-not-found diagnostics.
m-ou-se ce95a57
Update tests.
m-ou-se d834d2a
Silence confusing 'unused import' warnings.
m-ou-se 5dea5d7
Say what things are, instead of what they are not.
m-ou-se 4bd415f
Clarify what attribute and derive macros look like.
m-ou-se a13c66e
Don't confuse the user with notes about tool modules.
m-ou-se 4e22bf4
Show what things are, but also what they are not.
m-ou-se 908ce2f
Improve wording of macro-not-found-but-name-exists note.
m-ou-se File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// compile-flags: -Z deduplicate-diagnostics=yes | ||
|
||
#![warn(unused_imports)] | ||
|
||
use std::str::*; | ||
//~^ 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, X}; | ||
//~^ 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 | ||
|
||
#[derive(Serialize)] | ||
//~^ ERROR cannot find derive macro `Serialize` | ||
struct A; | ||
|
||
#[derive(from_utf8_mut)] | ||
//~^ ERROR cannot find derive macro `from_utf8_mut` | ||
struct B; | ||
|
||
#[derive(println)] | ||
//~^ ERROR cannot find derive macro `println` | ||
//~| NOTE `println` is in scope, but it is a function-like macro | ||
struct C; | ||
|
||
#[Deserialize] | ||
//~^ ERROR cannot find attribute `Deserialize` | ||
struct D; | ||
|
||
#[from_utf8_unchecked] | ||
//~^ ERROR cannot find attribute `from_utf8_unchecked` | ||
struct E; | ||
|
||
#[println] | ||
//~^ ERROR cannot find attribute `println` | ||
//~| NOTE `println` is in scope, but it is a function-like macro | ||
struct F; | ||
|
||
fn main() { | ||
from_utf8!(); | ||
//~^ ERROR cannot find macro `from_utf8` | ||
|
||
Box!(); | ||
//~^ ERROR cannot find macro `Box` | ||
//~| NOTE `Box` is in scope, but it is a struct | ||
|
||
Copy!(); | ||
//~^ ERROR cannot find macro `Copy` | ||
//~| NOTE `Copy` is in scope, but it is a derive macro | ||
|
||
test!(); | ||
//~^ ERROR cannot find macro `test` | ||
//~| NOTE `test` is in scope, but it is an attribute | ||
|
||
X!(); | ||
//~^ ERROR cannot find macro `X` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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, not a macro | ||
--> $DIR/issue-88206.rs:17:35 | ||
| | ||
LL | use hey::{Serialize, Deserialize, X}; | ||
| ^ | ||
|
||
error: cannot find macro `test` in this scope | ||
--> $DIR/issue-88206.rs:60:5 | ||
| | ||
LL | test!(); | ||
| ^^^^ | ||
| | ||
= note: `test` is in scope, but it is an attribute: `#[test]` | ||
|
||
error: cannot find macro `Copy` in this scope | ||
--> $DIR/issue-88206.rs:56:5 | ||
| | ||
LL | Copy!(); | ||
| ^^^^ | ||
| | ||
= note: `Copy` is in scope, but it is a derive macro: `#[derive(Copy)]` | ||
|
||
error: cannot find macro `Box` in this scope | ||
--> $DIR/issue-88206.rs:52:5 | ||
| | ||
LL | Box!(); | ||
| ^^^ | ||
| | ||
= note: `Box` is in scope, but it is a struct, not a macro | ||
|
||
error: cannot find macro `from_utf8` in this scope | ||
--> $DIR/issue-88206.rs:49:5 | ||
| | ||
LL | from_utf8!(); | ||
| ^^^^^^^^^ | ||
| | ||
note: `from_utf8` is imported here, but it is a function, not a macro | ||
--> $DIR/issue-88206.rs:5:5 | ||
| | ||
LL | use std::str::*; | ||
| ^^^^^^^^^^^ | ||
|
||
error: cannot find attribute `println` in this scope | ||
--> $DIR/issue-88206.rs:43:3 | ||
| | ||
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:39:3 | ||
| | ||
LL | #[from_utf8_unchecked] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: `from_utf8_unchecked` is imported here, but it is a function, not an attribute | ||
--> $DIR/issue-88206.rs:5:5 | ||
| | ||
LL | use std::str::*; | ||
| ^^^^^^^^^^^ | ||
|
||
error: cannot find attribute `Deserialize` in this scope | ||
--> $DIR/issue-88206.rs:35:3 | ||
| | ||
LL | #[Deserialize] | ||
| ^^^^^^^^^^^ | ||
| | ||
note: `Deserialize` is imported here, but it is a trait, not an attribute | ||
--> $DIR/issue-88206.rs:17:22 | ||
| | ||
LL | use hey::{Serialize, Deserialize, X}; | ||
| ^^^^^^^^^^^ | ||
|
||
error: cannot find derive macro `println` in this scope | ||
--> $DIR/issue-88206.rs:30:10 | ||
| | ||
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:26:10 | ||
| | ||
LL | #[derive(from_utf8_mut)] | ||
| ^^^^^^^^^^^^^ | ||
| | ||
note: `from_utf8_mut` is imported here, but it is a function, not a derive macro | ||
--> $DIR/issue-88206.rs:5:5 | ||
| | ||
LL | use std::str::*; | ||
| ^^^^^^^^^^^ | ||
|
||
error: cannot find derive macro `Serialize` in this scope | ||
--> $DIR/issue-88206.rs:22:10 | ||
| | ||
LL | #[derive(Serialize)] | ||
| ^^^^^^^^^ | ||
| | ||
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}; | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to 11 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the cases where we don't have a span, wouldn't it make sense to turn this into the primary span? Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid pointing the note at the identifier the user wrote, because the error already says
cannot find `Thing`
, and the note is about anotherThing
, not theThing
they wrote. (Even though they have the same name.)So in the case we can point at an import, we do that to highlight
Thing
here is not found, butThing
there exists but is something else. Pointing both at the same identifier would make it less clear that we're talking about two differentThing
s.