Skip to content

Show an actionable help text to add a "use ..." on error "cannot find macro" #102601

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

Open
nyurik opened this issue Oct 2, 2022 · 3 comments
Open
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nyurik
Copy link
Contributor

nyurik commented Oct 2, 2022

Given the following code:

fn main() {
    bitflags! {
        struct Flags: u32 {
            const A = 0b00000001;
        }
    }
}

The current output is:

error: cannot find macro `bitflags` in this scope
 --> src/main.rs:2:5
  |
2 |     bitflags! {
  |     ^^^^^^^^
  |
  = note: consider importing this macro:
          bitflags::bitflags
  = note: `bitflags` is in scope, but it is a crate, not a macro

The output should include an actionable help that tells novice users what to do in a way that can be copy/pasted, instead of just specifying which macro to use. Modeling after the error message of a missing type, the missing macro message should look like this (in green):

help: consider importing this macro
    |
1   | use bitflags::bitflags;
    |

Same for Derive macros

The same should also be done for the derive macros, e.g. instead of this:

error: cannot find derive macro `Bytenum` in this scope
 --> src/main.rs:4:10
  |
4 | #[derive(Bytenum, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
  |          ^^^^^^^
  |
  = help: consider importing this derive macro:
          bytenum::Bytenum

the help message should be

  = help: consider importing this derive macro:
    |
1   | use bytenum::Bytenum;
    |

Relevant code

See also the code that generates the message above: compiler/rustc_resolve/src/diagnostics.rs

@nyurik nyurik added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2022
@chenyukang
Copy link
Member

@rustbot claim

@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. labels Oct 3, 2022
@chenyukang chenyukang removed their assignment Oct 4, 2022
@togami2864
Copy link
Contributor

@rustbot claim

@nyurik
Copy link
Contributor Author

nyurik commented Mar 15, 2023

Apparently the derive macros also have this shortcoming, added an example above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants