about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/proc-macro/auxiliary/test-macros.rs22
-rw-r--r--src/test/ui/proc-macro/derive-helper-legacy-spurious.rs13
-rw-r--r--src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr28
-rw-r--r--src/test/ui/proc-macro/inert-attribute-order.rs23
-rw-r--r--src/test/ui/proc-macro/inert-attribute-order.stdout7
5 files changed, 87 insertions, 6 deletions
diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs
index 57a7ffa39ef..a7ed4bc8825 100644
--- a/src/test/ui/proc-macro/auxiliary/test-macros.rs
+++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs
@@ -7,7 +7,7 @@
 #![crate_type = "proc-macro"]
 
 extern crate proc_macro;
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream, TokenTree};
 
 // Macro that return empty token stream.
 
@@ -80,6 +80,10 @@ pub fn recollect_derive(input: TokenStream) -> TokenStream {
 // Macros that print their input in the original and re-collected forms (if they differ).
 
 fn print_helper(input: TokenStream, kind: &str) -> TokenStream {
+    print_helper_ext(input, kind, true)
+}
+
+fn print_helper_ext(input: TokenStream, kind: &str, debug: bool) -> TokenStream {
     let input_display = format!("{}", input);
     let input_debug = format!("{:#?}", input);
     let recollected = input.into_iter().collect();
@@ -89,9 +93,11 @@ fn print_helper(input: TokenStream, kind: &str) -> TokenStream {
     if recollected_display != input_display {
         println!("PRINT-{} RE-COLLECTED (DISPLAY): {}", kind, recollected_display);
     }
-    println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug);
-    if recollected_debug != input_debug {
-        println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug);
+    if debug {
+        println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug);
+        if recollected_debug != input_debug {
+            println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug);
+        }
     }
     recollected
 }
@@ -108,8 +114,12 @@ pub fn print_bang_consume(input: TokenStream) -> TokenStream {
 }
 
 #[proc_macro_attribute]
-pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream {
-    print_helper(input, "ATTR")
+pub fn print_attr(args: TokenStream, input: TokenStream) -> TokenStream {
+    let debug = match &args.into_iter().collect::<Vec<_>>()[..] {
+        [TokenTree::Ident(ident)] if ident.to_string() == "nodebug" => false,
+        _ => true,
+    };
+    print_helper_ext(input, "ATTR", debug)
 }
 
 #[proc_macro_attribute]
diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs
new file mode 100644
index 00000000000..8180aab0caa
--- /dev/null
+++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs
@@ -0,0 +1,13 @@
+// aux-build:test-macros.rs
+
+#![dummy] //~ ERROR cannot find attribute `dummy` in this scope
+
+#[macro_use]
+extern crate test_macros;
+
+#[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive`
+#[empty_helper] //~ WARN derive helper attribute is used before it is introduced
+                //~| WARN this was previously accepted
+struct Foo {}
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr
new file mode 100644
index 00000000000..96754fed993
--- /dev/null
+++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr
@@ -0,0 +1,28 @@
+error: cannot find attribute `dummy` in this scope
+  --> $DIR/derive-helper-legacy-spurious.rs:3:4
+   |
+LL | #![dummy]
+   |    ^^^^^
+
+error: cannot determine resolution for the attribute macro `derive`
+  --> $DIR/derive-helper-legacy-spurious.rs:8:3
+   |
+LL | #[derive(Empty)]
+   |   ^^^^^^
+   |
+   = note: import resolution is stuck, try simplifying macro imports
+
+warning: derive helper attribute is used before it is introduced
+  --> $DIR/derive-helper-legacy-spurious.rs:9:3
+   |
+LL | #[derive(Empty)]
+   |          ----- the attribute is introduced here
+LL | #[empty_helper]
+   |   ^^^^^^^^^^^^
+   |
+   = note: `#[warn(legacy_derive_helpers)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
diff --git a/src/test/ui/proc-macro/inert-attribute-order.rs b/src/test/ui/proc-macro/inert-attribute-order.rs
new file mode 100644
index 00000000000..f8079675641
--- /dev/null
+++ b/src/test/ui/proc-macro/inert-attribute-order.rs
@@ -0,0 +1,23 @@
+// Order of inert attributes, both built-in and custom is preserved during expansion.
+
+// check-pass
+// compile-flags: -Z span-debug
+// aux-build:test-macros.rs
+
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
+
+#[macro_use]
+extern crate test_macros;
+
+/// 1
+#[rustfmt::attr2]
+#[doc = "3"]
+#[print_attr(nodebug)]
+#[doc = "4"]
+#[rustfmt::attr5]
+/// 6
+#[print_attr(nodebug)]
+struct S;
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/inert-attribute-order.stdout b/src/test/ui/proc-macro/inert-attribute-order.stdout
new file mode 100644
index 00000000000..7c0620b50b3
--- /dev/null
+++ b/src/test/ui/proc-macro/inert-attribute-order.stdout
@@ -0,0 +1,7 @@
+PRINT-ATTR INPUT (DISPLAY): /// 1
+#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6
+#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"]
+#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ;
+PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2]
+#[rustfmt :: attr5] struct S ;