Skip to content
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
merged 11 commits into from
Aug 23, 2021

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Aug 22, 2021

This adds notes like:

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 not a derive macro
  --> $DIR/issue-88206.rs:17:11
   |
LL | use hey::{Serialize, Deserialize};
   |           ^^^^^^^^^

Fixes #88206

Includes #88229

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2021
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love how these are looking 😃

I'm leaving some nitpicks, but we don't need to address them all to land this.

compiler/rustc_resolve/src/diagnostics.rs Outdated Show resolved Hide resolved
src/test/ui/issues/issue-11692-2.stderr Outdated Show resolved Hide resolved
src/test/ui/macros/issue-88206.stderr Outdated Show resolved Hide resolved
@@ -32,15 +32,15 @@ error: cannot find macro `Box` in this scope
LL | Box!();
| ^^^
|
= note: `Box` is in scope, but it is a struct
= note: `Box` is in scope, but it is a struct, not a macro
Copy link
Contributor

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:

error: cannot find macro `Copy` in this scope
  --> $DIR/issue-88206.rs:56:5
   |
LL |     Copy!();
   |     ^^^^ this is not a macro, it is a derive macro: `#[derive(Copy)]`

Copy link
Member Author

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 another Thing, not the Thing 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, but Thing there exists but is something else. Pointing both at the same identifier would make it less clear that we're talking about two different Things.

@m-ou-se m-ou-se force-pushed the macro-name-imported-but-not-macro branch 2 times, most recently from bacb1c8 to 908ce2f Compare August 23, 2021 14:58
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2021

📌 Commit 908ce2f has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 23, 2021
Rollup of 6 pull requests

Successful merges:

 - rust-lang#87976 (Account for tabs when highlighting multiline code suggestions)
 - rust-lang#88174 (Clarify some wording in Rust 2021 lint docs)
 - rust-lang#88188 (Greatly improve limitation handling on parallel rustdoc GUI test run)
 - rust-lang#88230 (Fix typos “a”→“an”)
 - rust-lang#88232 (Add notes to macro-not-found diagnostics to point out how things with the same name were not a match.)
 - rust-lang#88259 (Do not mark `-Z thir-unsafeck` as unsound anymore)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c31e02a into rust-lang:master Aug 23, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 23, 2021
@m-ou-se m-ou-se deleted the macro-name-imported-but-not-macro branch July 1, 2022 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing diagnostics on #[derive(X)] when X is imported only as trait
5 participants