diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-10-17 05:36:32 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-17 05:36:32 +0900 |
| commit | 7581bb7c02f9960fba66add3e4c7c62874c60c7f (patch) | |
| tree | 4e48ad8722a26a5bb1b249d5ec034a9126de1dbf | |
| parent | 5a51185fd4600e96cc79a3db9da3c4bf927f2281 (diff) | |
| parent | ea7cf6106864ce7929eb9f3cfe580f05ee418ac8 (diff) | |
| download | rust-7581bb7c02f9960fba66add3e4c7c62874c60c7f.tar.gz rust-7581bb7c02f9960fba66add3e4c7c62874c60c7f.zip | |
Rollup merge of #75209 - Hirrolot:suggest-macro-imports, r=estebank
Suggest imports of unresolved macros Closes https://github.com/rust-lang/rust/issues/75191.
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/empty/empty-macro-use.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/hygiene/no_implicit_prelude-2018.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/hygiene/no_implicit_prelude.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/macros/macro-use-wrong-name.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/missing/missing-macro-use.stderr | 3 |
6 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 774a147c114..33ab09a8f42 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -922,6 +922,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); diff --git a/src/test/ui/empty/empty-macro-use.stderr b/src/test/ui/empty/empty-macro-use.stderr index 8e3e06896ee..700f6616af4 100644 --- a/src/test/ui/empty/empty-macro-use.stderr +++ b/src/test/ui/empty/empty-macro-use.stderr @@ -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 diff --git a/src/test/ui/hygiene/no_implicit_prelude-2018.stderr b/src/test/ui/hygiene/no_implicit_prelude-2018.stderr index f31b75238df..02ddc391f6e 100644 --- a/src/test/ui/hygiene/no_implicit_prelude-2018.stderr +++ b/src/test/ui/hygiene/no_implicit_prelude-2018.stderr @@ -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 diff --git a/src/test/ui/hygiene/no_implicit_prelude.stderr b/src/test/ui/hygiene/no_implicit_prelude.stderr index 3c0c0450774..843dee2478b 100644 --- a/src/test/ui/hygiene/no_implicit_prelude.stderr +++ b/src/test/ui/hygiene/no_implicit_prelude.stderr @@ -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` diff --git a/src/test/ui/macros/macro-use-wrong-name.stderr b/src/test/ui/macros/macro-use-wrong-name.stderr index 74fb519cc82..888fb913fb7 100644 --- a/src/test/ui/macros/macro-use-wrong-name.stderr +++ b/src/test/ui/macros/macro-use-wrong-name.stderr @@ -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 diff --git a/src/test/ui/missing/missing-macro-use.stderr b/src/test/ui/missing/missing-macro-use.stderr index 711e249d2bc..ced062269df 100644 --- a/src/test/ui/missing/missing-macro-use.stderr +++ b/src/test/ui/missing/missing-macro-use.stderr @@ -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 |
