diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 2054b7a351f..f111a44efe0 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -669,7 +669,10 @@ enum WhereToResolve<'a> { } } WhereToResolve::BuiltinAttrs => { - if is_builtin_attr_name(ident.name) { + // FIXME: Only built-in attributes are not considered as candidates for + // non-attributes to fight off regressions on stable channel (#53205). + // We need to come up with some more principled approach instead. + if is_attr && is_builtin_attr_name(ident.name) { let binding = (Def::NonMacroAttr(NonMacroAttrKind::Builtin), ty::Visibility::Public, ident.span, Mark::root()) .to_name_binding(self.arenas); diff --git a/src/test/ui/issue-11692-2.rs b/src/test/ui/issue-11692-2.rs index 50525e03acf..acac2d151fe 100644 --- a/src/test/ui/issue-11692-2.rs +++ b/src/test/ui/issue-11692-2.rs @@ -10,5 +10,5 @@ fn main() { concat!(test!()); - //~^ ERROR expected a macro, found built-in attribute + //~^ ERROR cannot find macro `test!` in this scope } diff --git a/src/test/ui/issue-11692-2.stderr b/src/test/ui/issue-11692-2.stderr index 0c130943fd8..51d6041e922 100644 --- a/src/test/ui/issue-11692-2.stderr +++ b/src/test/ui/issue-11692-2.stderr @@ -1,4 +1,4 @@ -error: expected a macro, found built-in attribute +error: cannot find macro `test!` in this scope --> $DIR/issue-11692-2.rs:12:13 | LL | concat!(test!()); diff --git a/src/test/ui/macro-path-prelude-fail-3.rs b/src/test/ui/macro-path-prelude-fail-3.rs index bdbc7bd660f..d325b046001 100644 --- a/src/test/ui/macro-path-prelude-fail-3.rs +++ b/src/test/ui/macro-path-prelude-fail-3.rs @@ -10,9 +10,9 @@ #![feature(use_extern_macros)] -#[derive(inline)] //~ ERROR expected a macro, found built-in attribute +#[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope struct S; fn main() { - inline!(); //~ ERROR expected a macro, found built-in attribute + inline!(); //~ ERROR cannot find macro `inline!` in this scope } diff --git a/src/test/ui/macro-path-prelude-fail-3.stderr b/src/test/ui/macro-path-prelude-fail-3.stderr index 396bba2408f..c9af4b66427 100644 --- a/src/test/ui/macro-path-prelude-fail-3.stderr +++ b/src/test/ui/macro-path-prelude-fail-3.stderr @@ -1,14 +1,14 @@ -error: expected a macro, found built-in attribute +error: cannot find derive macro `inline` in this scope --> $DIR/macro-path-prelude-fail-3.rs:13:10 | -LL | #[derive(inline)] //~ ERROR expected a macro, found built-in attribute +LL | #[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope | ^^^^^^ -error: expected a macro, found built-in attribute +error: cannot find macro `inline!` in this scope --> $DIR/macro-path-prelude-fail-3.rs:17:5 | -LL | inline!(); //~ ERROR expected a macro, found built-in attribute - | ^^^^^^ +LL | inline!(); //~ ERROR cannot find macro `inline!` in this scope + | ^^^^^^ help: you could try the macro: `line` error: aborting due to 2 previous errors diff --git a/src/test/ui/macro-path-prelude-shadowing.rs b/src/test/ui/macro-path-prelude-shadowing.rs index 1aff7777ef7..6831cd81d7d 100644 --- a/src/test/ui/macro-path-prelude-shadowing.rs +++ b/src/test/ui/macro-path-prelude-shadowing.rs @@ -21,7 +21,9 @@ macro_rules! add_macro_expanded_things_to_macro_prelude {() => { mod m1 { fn check() { - inline!(); //~ ERROR `inline` is ambiguous + inline!(); // OK. Theoretically ambiguous, but we do not consider built-in attributes + // as candidates for non-attribute macro invocations to avoid regressions + // on stable channel } } diff --git a/src/test/ui/macro-path-prelude-shadowing.stderr b/src/test/ui/macro-path-prelude-shadowing.stderr index 0e1b9a985a3..c0892f97376 100644 --- a/src/test/ui/macro-path-prelude-shadowing.stderr +++ b/src/test/ui/macro-path-prelude-shadowing.stderr @@ -1,42 +1,21 @@ -error[E0659]: `inline` is ambiguous - --> $DIR/macro-path-prelude-shadowing.rs:24:9 - | -LL | inline!(); //~ ERROR `inline` is ambiguous - | ^^^^^^ - | -note: `inline` could refer to the name imported here - --> $DIR/macro-path-prelude-shadowing.rs:16:5 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ -... -LL | add_macro_expanded_things_to_macro_prelude!(); - | ---------------------------------------------- in this macro invocation -note: `inline` could also refer to the name defined here - --> $DIR/macro-path-prelude-shadowing.rs:24:9 - | -LL | inline!(); //~ ERROR `inline` is ambiguous - | ^^^^^^ - = note: macro-expanded macro imports do not shadow - error[E0659]: `std` is ambiguous - --> $DIR/macro-path-prelude-shadowing.rs:37:9 + --> $DIR/macro-path-prelude-shadowing.rs:39:9 | LL | std::panic!(); //~ ERROR `std` is ambiguous | ^^^^^^^^^^ | note: `std` could refer to the name imported here - --> $DIR/macro-path-prelude-shadowing.rs:35:9 + --> $DIR/macro-path-prelude-shadowing.rs:37:9 | LL | use m2::*; // glob-import user-defined `std` | ^^^^^ note: `std` could also refer to the name defined here - --> $DIR/macro-path-prelude-shadowing.rs:37:9 + --> $DIR/macro-path-prelude-shadowing.rs:39:9 | LL | std::panic!(); //~ ERROR `std` is ambiguous | ^^^ = note: consider adding an explicit import of `std` to disambiguate -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0659`.