Skip to content

Commit e7ee6fb

Browse files
committed
Do not consider built-in attributes as candidates when resolving non-attribute macro invocations
This is needed to avoid regressions on stable channel
1 parent d2f5637 commit e7ee6fb

7 files changed

+20
-36
lines changed

src/librustc_resolve/macros.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
669669
}
670670
}
671671
WhereToResolve::BuiltinAttrs => {
672-
if is_builtin_attr_name(ident.name) {
672+
// FIXME: Only built-in attributes are not considered as candidates for
673+
// non-attributes to fight off regressions on stable channel (#53205).
674+
// We need to come up with some more principled approach instead.
675+
if is_attr && is_builtin_attr_name(ident.name) {
673676
let binding = (Def::NonMacroAttr(NonMacroAttrKind::Builtin),
674677
ty::Visibility::Public, ident.span, Mark::root())
675678
.to_name_binding(self.arenas);

src/test/ui/issue-11692-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
concat!(test!());
13-
//~^ ERROR expected a macro, found built-in attribute
13+
//~^ ERROR cannot find macro `test!` in this scope
1414
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: expected a macro, found built-in attribute
1+
error: cannot find macro `test!` in this scope
22
--> $DIR/issue-11692-2.rs:12:13
33
|
44
LL | concat!(test!());

src/test/ui/macro-path-prelude-fail-3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
#![feature(use_extern_macros)]
1212

13-
#[derive(inline)] //~ ERROR expected a macro, found built-in attribute
13+
#[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
1414
struct S;
1515

1616
fn main() {
17-
inline!(); //~ ERROR expected a macro, found built-in attribute
17+
inline!(); //~ ERROR cannot find macro `inline!` in this scope
1818
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error: expected a macro, found built-in attribute
1+
error: cannot find derive macro `inline` in this scope
22
--> $DIR/macro-path-prelude-fail-3.rs:13:10
33
|
4-
LL | #[derive(inline)] //~ ERROR expected a macro, found built-in attribute
4+
LL | #[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
55
| ^^^^^^
66

7-
error: expected a macro, found built-in attribute
7+
error: cannot find macro `inline!` in this scope
88
--> $DIR/macro-path-prelude-fail-3.rs:17:5
99
|
10-
LL | inline!(); //~ ERROR expected a macro, found built-in attribute
11-
| ^^^^^^
10+
LL | inline!(); //~ ERROR cannot find macro `inline!` in this scope
11+
| ^^^^^^ help: you could try the macro: `line`
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/macro-path-prelude-shadowing.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ add_macro_expanded_things_to_macro_prelude!();
2121

2222
mod m1 {
2323
fn check() {
24-
inline!(); //~ ERROR `inline` is ambiguous
24+
inline!(); // OK. Theoretically ambiguous, but we do not consider built-in attributes
25+
// as candidates for non-attribute macro invocations to avoid regressions
26+
// on stable channel
2527
}
2628
}
2729

Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
error[E0659]: `inline` is ambiguous
2-
--> $DIR/macro-path-prelude-shadowing.rs:24:9
3-
|
4-
LL | inline!(); //~ ERROR `inline` is ambiguous
5-
| ^^^^^^
6-
|
7-
note: `inline` could refer to the name imported here
8-
--> $DIR/macro-path-prelude-shadowing.rs:16:5
9-
|
10-
LL | #[macro_use]
11-
| ^^^^^^^^^^^^
12-
...
13-
LL | add_macro_expanded_things_to_macro_prelude!();
14-
| ---------------------------------------------- in this macro invocation
15-
note: `inline` could also refer to the name defined here
16-
--> $DIR/macro-path-prelude-shadowing.rs:24:9
17-
|
18-
LL | inline!(); //~ ERROR `inline` is ambiguous
19-
| ^^^^^^
20-
= note: macro-expanded macro imports do not shadow
21-
221
error[E0659]: `std` is ambiguous
23-
--> $DIR/macro-path-prelude-shadowing.rs:37:9
2+
--> $DIR/macro-path-prelude-shadowing.rs:39:9
243
|
254
LL | std::panic!(); //~ ERROR `std` is ambiguous
265
| ^^^^^^^^^^
276
|
287
note: `std` could refer to the name imported here
29-
--> $DIR/macro-path-prelude-shadowing.rs:35:9
8+
--> $DIR/macro-path-prelude-shadowing.rs:37:9
309
|
3110
LL | use m2::*; // glob-import user-defined `std`
3211
| ^^^^^
3312
note: `std` could also refer to the name defined here
34-
--> $DIR/macro-path-prelude-shadowing.rs:37:9
13+
--> $DIR/macro-path-prelude-shadowing.rs:39:9
3514
|
3615
LL | std::panic!(); //~ ERROR `std` is ambiguous
3716
| ^^^
3817
= note: consider adding an explicit import of `std` to disambiguate
3918

40-
error: aborting due to 2 previous errors
19+
error: aborting due to previous error
4120

4221
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)