Skip to content

Commit ea7cf61

Browse files
committed
Don't suggest macros that out of scope
1 parent 479298e commit ea7cf61

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,15 @@ impl<'a> Resolver<'a> {
929929
);
930930
self.add_typo_suggestion(err, suggestion, ident.span);
931931

932-
let import_suggestions =
933-
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, |_| true);
932+
let import_suggestions = self.lookup_import_candidates(
933+
ident,
934+
Namespace::MacroNS,
935+
parent_scope,
936+
|res| match res {
937+
Res::Def(DefKind::Macro(MacroKind::Bang), _) => true,
938+
_ => false,
939+
},
940+
);
934941
show_candidates(err, None, &import_suggestions, false, true);
935942

936943
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {

src/test/ui/issues/issue-11692-2.stderr

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

107
error: aborting due to previous error
118

src/test/ui/proc-macro/derive-helper-shadowing.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ error: cannot find attribute `empty_helper` in this scope
1616
LL | #[derive(GenHelperUse)]
1717
| ^^^^^^^^^^^^
1818
|
19-
= note: consider importing this attribute macro:
20-
empty_helper
2119
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
2220

2321
error: cannot find attribute `empty_helper` in this scope
@@ -29,8 +27,6 @@ LL | #[empty_helper]
2927
LL | gen_helper_use!();
3028
| ------------------ in this macro invocation
3129
|
32-
= note: consider importing this attribute macro:
33-
crate::empty_helper
3430
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3531

3632
error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)

src/test/ui/proc-macro/macro-namespace-reserved-2.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,12 @@ error: cannot find macro `my_macro_attr` in this scope
9393
|
9494
LL | my_macro_attr!();
9595
| ^^^^^^^^^^^^^
96-
|
97-
= note: consider importing this attribute macro:
98-
my_macro_attr
9996

10097
error: cannot find macro `MyTrait` in this scope
10198
--> $DIR/macro-namespace-reserved-2.rs:33:5
10299
|
103100
LL | MyTrait!();
104101
| ^^^^^^^
105-
|
106-
= note: consider importing this derive macro:
107-
MyTrait
108102

109103
error: cannot find attribute `my_macro` in this scope
110104
--> $DIR/macro-namespace-reserved-2.rs:38:3

0 commit comments

Comments
 (0)