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

Suggest imports of unresolved macros #75209

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,17 @@ impl<'a> Resolver<'a> {
);
self.add_typo_suggestion(err, suggestion, ident.span);

let import_suggestions = self.lookup_import_candidates(
ident,
Namespace::MacroNS,
parent_scope,
|res| match res {
Res::Def(DefKind::Macro(MacroKind::Bang), _) => true,
_ => false,
},
);
show_candidates(err, None, &import_suggestions, false, true);

if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
let msg = format!("unsafe traits like `{}` should be implemented explicitly", ident);
err.span_note(ident.span, &msg);
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/empty/empty-macro-use.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: cannot find macro `macro_two` in this scope
|
LL | macro_two!();
| ^^^^^^^^^
|
= note: consider importing this macro:
two_macros::macro_two

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/hygiene/no_implicit_prelude-2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: cannot find macro `print` in this scope
|
LL | print!();
| ^^^^^
|
= note: consider importing this macro:
std::print

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/hygiene/no_implicit_prelude.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ error: cannot find macro `panic` in this scope
LL | assert_eq!(0, 0);
| ^^^^^^^^^^^^^^^^^
|
= note: consider importing one of these items:
core::panic
std::panic
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Vec`
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/macros/macro-use-wrong-name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ LL | macro_two!();
|
LL | macro_rules! macro_one { () => ("one") }
| ---------------------- similarly named macro `macro_one` defined here
|
= note: consider importing this macro:
two_macros::macro_two

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/missing/missing-macro-use.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: cannot find macro `macro_two` in this scope
|
LL | macro_two!();
| ^^^^^^^^^
|
= note: consider importing this macro:
two_macros::macro_two

error: aborting due to previous error