]> git.lizzy.rs Git - rust.git/commitdiff
Do not consider built-in attributes as candidates when resolving non-attribute macro...
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 11 Aug 2018 13:58:28 +0000 (16:58 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 11 Aug 2018 14:02:47 +0000 (17:02 +0300)
This is needed to avoid regressions on stable channel

src/librustc_resolve/macros.rs
src/test/ui/issue-11692-2.rs
src/test/ui/issue-11692-2.stderr
src/test/ui/macro-path-prelude-fail-3.rs
src/test/ui/macro-path-prelude-fail-3.stderr
src/test/ui/macro-path-prelude-shadowing.rs
src/test/ui/macro-path-prelude-shadowing.stderr

index 2054b7a351f7d80028c4300240aa620f7fd94075..f111a44efe05b6d323bc807f7f034cb534041470 100644 (file)
@@ -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);
index 50525e03acf50cebfe0db56e82262cbdf6ddc9c9..acac2d151fe9ad5ef8008d3caf10f1a5de111bf7 100644 (file)
@@ -10,5 +10,5 @@
 
 fn main() {
     concat!(test!());
-    //~^ ERROR expected a macro, found built-in attribute
+    //~^ ERROR cannot find macro `test!` in this scope
 }
index 0c130943fd873e789d5d828bc21f1eb228f3791a..51d6041e92220e356b6f873a9ec54c9c8e5ca952 100644 (file)
@@ -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!());
index bdbc7bd660fcdaf0f9cdbbfd8adfd0f91834733f..d325b0460015c7f18660ce555e42aa0136757b44 100644 (file)
@@ -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
 }
index 396bba2408f32231b07f5630100810ff18167b63..c9af4b66427516df4a674b863d0a2c7b5e68d057 100644 (file)
@@ -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
 
index 1aff7777ef7b1d306e8ffc632a3093af75851267..6831cd81d7daebffc0291d15a21f65ca8a21d74b 100644 (file)
@@ -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
     }
 }
 
index 0e1b9a985a3c378d8cfc86ab144bdb6eaa06d582..c0892f97376e32fd0ccbacdfb5824f824395957a 100644 (file)
@@ -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`.