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
rustc: always suggests #[macro_use] for undefined macros #37910
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
it looks like @arielb1 never reviewed. Maybe someone else from @rust-lang/compiler ? |
r? @jseyfried |
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.
@liigo Thanks for the PR!
Let me know here or on IRC if you have any questions about my comments.
@@ -385,10 +385,9 @@ impl<'a> Resolver<'a> { | |||
if let Some(suggestion) = find_best_match_for_name(self.macro_names.iter(), name, None) { | |||
if suggestion != name { | |||
err.help(&format!("did you mean `{}!`?", suggestion)); | |||
} else { | |||
err.help(&format!("have you added the `#[macro_use]` on the module/import?")); |
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 think we should keep this here, but it should just say "have you added the #[macro_use]
on the module?".
} | ||
} | ||
err.help(&format!("have you added the `#[macro_use]` on the module/import?")); |
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 think this should say "have you added the #[macro_use]
on the extern crate
", but only if there is a macro with that name in an extern crate.
You should be able to use resolver.lookup_import_candidates()
(in librustc_resolve/lib.rs
) with a filter_fn
that checks for Def::Macro
s to see if there are any relevant macros in extern crate
s that the user might want to #[macro_use]
.
Hmm, with this change, if I write: #[macro_use]
extern crate log;
fn main() {
infq!("hello");
} won't the compiler now suggest I put in a Update: oops, @jseyfried 's feedback has already covered this; I needed to refresh my page. |
I'll try to work on according to review suggestions. Please don't merge util I'm done. |
Closing due to inactivity, but feel free to resubmit with comments addressed! |
Work in progress. Don't merge.
If people forget adding
#[macro_use]
(or even don't know about it), give them a suggestion.play link: https://is.gd/nwB6ty