Skip to content

Commit 7581bb7

Browse files
authored
Rollup merge of #75209 - Hirrolot:suggest-macro-imports, r=estebank
Suggest imports of unresolved macros Closes #75191.
2 parents 5a51185 + ea7cf61 commit 7581bb7

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

Diff for: compiler/rustc_resolve/src/diagnostics.rs

+11
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,17 @@ impl<'a> Resolver<'a> {
922922
);
923923
self.add_typo_suggestion(err, suggestion, ident.span);
924924

925+
let import_suggestions = self.lookup_import_candidates(
926+
ident,
927+
Namespace::MacroNS,
928+
parent_scope,
929+
|res| match res {
930+
Res::Def(DefKind::Macro(MacroKind::Bang), _) => true,
931+
_ => false,
932+
},
933+
);
934+
show_candidates(err, None, &import_suggestions, false, true);
935+
925936
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
926937
let msg = format!("unsafe traits like `{}` should be implemented explicitly", ident);
927938
err.span_note(ident.span, &msg);

Diff for: src/test/ui/empty/empty-macro-use.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: cannot find macro `macro_two` in this scope
33
|
44
LL | macro_two!();
55
| ^^^^^^^^^
6+
|
7+
= note: consider importing this macro:
8+
two_macros::macro_two
69

710
error: aborting due to previous error
811

Diff for: src/test/ui/hygiene/no_implicit_prelude-2018.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: cannot find macro `print` in this scope
33
|
44
LL | print!();
55
| ^^^^^
6+
|
7+
= note: consider importing this macro:
8+
std::print
69

710
error: aborting due to previous error
811

Diff for: src/test/ui/hygiene/no_implicit_prelude.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ error: cannot find macro `panic` in this scope
44
LL | assert_eq!(0, 0);
55
| ^^^^^^^^^^^^^^^^^
66
|
7+
= note: consider importing one of these items:
8+
core::panic
9+
std::panic
710
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
811

912
error[E0433]: failed to resolve: use of undeclared type `Vec`

Diff for: src/test/ui/macros/macro-use-wrong-name.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ LL | macro_two!();
88
|
99
LL | macro_rules! macro_one { () => ("one") }
1010
| ---------------------- similarly named macro `macro_one` defined here
11+
|
12+
= note: consider importing this macro:
13+
two_macros::macro_two
1114

1215
error: aborting due to previous error
1316

Diff for: src/test/ui/missing/missing-macro-use.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: cannot find macro `macro_two` in this scope
33
|
44
LL | macro_two!();
55
| ^^^^^^^^^
6+
|
7+
= note: consider importing this macro:
8+
two_macros::macro_two
69

710
error: aborting due to previous error
811

0 commit comments

Comments
 (0)