]> git.lizzy.rs Git - rust.git/commitdiff
Add some more tests
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 5 Oct 2019 13:59:52 +0000 (16:59 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 16 Nov 2019 15:31:55 +0000 (18:31 +0300)
src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs [new file with mode: 0644]
src/test/ui/proc-macro/derive-helper-shadowing.rs
src/test/ui/proc-macro/derive-helper-shadowing.stderr

diff --git a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs
new file mode 100644 (file)
index 0000000..41d3a18
--- /dev/null
@@ -0,0 +1,15 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::*;
+
+#[proc_macro_derive(GenHelperUse)]
+pub fn derive_a(_: TokenStream) -> TokenStream {
+    "
+    #[empty_helper]
+    struct Uwu;
+    ".parse().unwrap()
+}
index fe324ae63cd33b6e1092a2f66bf83398e52653b3..f0ca34db414d441b539f851363813f9f4ff1b83c 100644 (file)
@@ -1,11 +1,21 @@
 // edition:2018
 // aux-build:test-macros.rs
+// aux-build:derive-helper-shadowing.rs
 
 #[macro_use]
 extern crate test_macros;
+#[macro_use]
+extern crate derive_helper_shadowing;
 
 use test_macros::empty_attr as empty_helper;
 
+macro_rules! gen_helper_use {
+    () => {
+        #[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
+        struct W;
+    }
+}
+
 #[empty_helper] //~ ERROR `empty_helper` is ambiguous
 #[derive(Empty)]
 struct S {
@@ -20,12 +30,25 @@ mod inner {
             // OK, no ambiguity, the non-helper attribute is not in scope here, only the helper.
             #[empty_helper]
             struct V;
+
+            gen_helper_use!();
+
+            #[derive(GenHelperUse)] //~ ERROR cannot find attribute `empty_helper` in this scope
+            struct Owo;
+
+            use empty_helper as renamed;
+            #[renamed] //~ ERROR cannot use a derive helper attribute through an import
+            struct Wow;
         }
 
         0
     }]
 }
 
+// OK, no ambiguity, only the non-helper attribute is in scope.
+#[empty_helper]
+struct Z;
+
 fn main() {
     let s = S { field: [] };
 }
index 66ce34799da8976edae19e2c95cdef70205347ed..9048830bee24d5f14d932025c1bfe2fffed5d4c6 100644 (file)
+error: cannot use a derive helper attribute through an import
+  --> $DIR/derive-helper-shadowing.rs:40:15
+   |
+LL |             #[renamed]
+   |               ^^^^^^^
+   |
+note: the derive helper attribute imported here
+  --> $DIR/derive-helper-shadowing.rs:39:17
+   |
+LL |             use empty_helper as renamed;
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: cannot find attribute `empty_helper` in this scope
+  --> $DIR/derive-helper-shadowing.rs:36:22
+   |
+LL |             #[derive(GenHelperUse)]
+   |                      ^^^^^^^^^^^^
+
+error: cannot find attribute `empty_helper` in this scope
+  --> $DIR/derive-helper-shadowing.rs:14:11
+   |
+LL |         #[empty_helper]
+   |           ^^^^^^^^^^^^
+...
+LL |             gen_helper_use!();
+   |             ------------------ in this macro invocation
+
 error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)
-  --> $DIR/derive-helper-shadowing.rs:14:13
+  --> $DIR/derive-helper-shadowing.rs:24:13
    |
 LL |         use empty_helper;
    |             ^^^^^^^^^^^^ ambiguous name
    |
 note: `empty_helper` could refer to the derive helper attribute defined here
-  --> $DIR/derive-helper-shadowing.rs:10:10
+  --> $DIR/derive-helper-shadowing.rs:20:10
    |
 LL | #[derive(Empty)]
    |          ^^^^^
 note: `empty_helper` could also refer to the attribute macro imported here
-  --> $DIR/derive-helper-shadowing.rs:7:5
+  --> $DIR/derive-helper-shadowing.rs:10:5
    |
 LL | use test_macros::empty_attr as empty_helper;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: use `crate::empty_helper` to refer to this attribute macro unambiguously
 
 error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
-  --> $DIR/derive-helper-shadowing.rs:9:3
+  --> $DIR/derive-helper-shadowing.rs:19:3
    |
 LL | #[empty_helper]
    |   ^^^^^^^^^^^^ ambiguous name
    |
 note: `empty_helper` could refer to the derive helper attribute defined here
-  --> $DIR/derive-helper-shadowing.rs:10:10
+  --> $DIR/derive-helper-shadowing.rs:20:10
    |
 LL | #[derive(Empty)]
    |          ^^^^^
 note: `empty_helper` could also refer to the attribute macro imported here
-  --> $DIR/derive-helper-shadowing.rs:7:5
+  --> $DIR/derive-helper-shadowing.rs:10:5
    |
 LL | use test_macros::empty_attr as empty_helper;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: use `crate::empty_helper` to refer to this attribute macro unambiguously
 
 error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
-  --> $DIR/derive-helper-shadowing.rs:12:7
+  --> $DIR/derive-helper-shadowing.rs:22:7
    |
 LL |     #[empty_helper]
    |       ^^^^^^^^^^^^ ambiguous name
    |
 note: `empty_helper` could refer to the derive helper attribute defined here
-  --> $DIR/derive-helper-shadowing.rs:10:10
+  --> $DIR/derive-helper-shadowing.rs:20:10
    |
 LL | #[derive(Empty)]
    |          ^^^^^
 note: `empty_helper` could also refer to the attribute macro imported here
-  --> $DIR/derive-helper-shadowing.rs:7:5
+  --> $DIR/derive-helper-shadowing.rs:10:5
    |
 LL | use test_macros::empty_attr as empty_helper;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: use `crate::empty_helper` to refer to this attribute macro unambiguously
 
 error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name)
-  --> $DIR/derive-helper-shadowing.rs:16:11
+  --> $DIR/derive-helper-shadowing.rs:26:11
    |
 LL |         #[empty_helper]
    |           ^^^^^^^^^^^^ ambiguous name
    |
 note: `empty_helper` could refer to the derive helper attribute defined here
-  --> $DIR/derive-helper-shadowing.rs:10:10
+  --> $DIR/derive-helper-shadowing.rs:20:10
    |
 LL | #[derive(Empty)]
    |          ^^^^^
 note: `empty_helper` could also refer to the attribute macro imported here
-  --> $DIR/derive-helper-shadowing.rs:7:5
+  --> $DIR/derive-helper-shadowing.rs:10:5
    |
 LL | use test_macros::empty_attr as empty_helper;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: use `crate::empty_helper` to refer to this attribute macro unambiguously
 
-error: aborting due to 4 previous errors
+error: aborting due to 7 previous errors
 
 For more information about this error, try `rustc --explain E0659`.