about summary refs log tree commit diff
path: root/src/test/ui/proc-macro
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-04-08 21:35:24 -0400
committerAaron Hill <aa1ronham@gmail.com>2021-04-10 17:29:20 -0400
commit21e6cc19fe3740d4e8d45866b053e774fc010209 (patch)
tree3f427120552bf7b5ea79ba48c5629170e6b820a0 /src/test/ui/proc-macro
parent2e495d2e845cf27740e3665f718acfd3aa17253e (diff)
downloadrust-21e6cc19fe3740d4e8d45866b053e774fc010209.tar.gz
rust-21e6cc19fe3740d4e8d45866b053e774fc010209.zip
Expand derive invocations in left-to-right order
While derives were being collected in left-to-order order, the
corresponding `Invocation`s were being pushed in the wrong order.
Diffstat (limited to 'src/test/ui/proc-macro')
-rw-r--r--src/test/ui/proc-macro/attribute-after-derive.stdout32
-rw-r--r--src/test/ui/proc-macro/auxiliary/multiple-derives.rs22
-rw-r--r--src/test/ui/proc-macro/derive-expand-order.rs14
-rw-r--r--src/test/ui/proc-macro/derive-expand-order.stdout5
-rw-r--r--src/test/ui/proc-macro/issue-36935.stderr16
5 files changed, 65 insertions, 24 deletions
diff --git a/src/test/ui/proc-macro/attribute-after-derive.stdout b/src/test/ui/proc-macro/attribute-after-derive.stdout
index 11f49235327..d0b66551919 100644
--- a/src/test/ui/proc-macro/attribute-after-derive.stdout
+++ b/src/test/ui/proc-macro/attribute-after-derive.stdout
@@ -99,22 +99,6 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
         span: $DIR/attribute-after-derive.rs:18:1: 21:2 (#0),
     },
 ]
-PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { }
-PRINT-ATTR INPUT (DEBUG): TokenStream [
-    Ident {
-        ident: "struct",
-        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
-    },
-    Ident {
-        ident: "DeriveAttribute",
-        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
-    },
-    Group {
-        delimiter: Brace,
-        stream: TokenStream [],
-        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
-    },
-]
 PRINT-DERIVE INPUT (DISPLAY): #[print_attr] struct DeriveAttribute { }
 PRINT-DERIVE INPUT (DEBUG): TokenStream [
     Punct {
@@ -146,3 +130,19 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
         span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
     },
 ]
+PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { }
+PRINT-ATTR INPUT (DEBUG): TokenStream [
+    Ident {
+        ident: "struct",
+        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
+    },
+    Ident {
+        ident: "DeriveAttribute",
+        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
+    },
+    Group {
+        delimiter: Brace,
+        stream: TokenStream [],
+        span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
+    },
+]
diff --git a/src/test/ui/proc-macro/auxiliary/multiple-derives.rs b/src/test/ui/proc-macro/auxiliary/multiple-derives.rs
new file mode 100644
index 00000000000..e3f6607b2ae
--- /dev/null
+++ b/src/test/ui/proc-macro/auxiliary/multiple-derives.rs
@@ -0,0 +1,22 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+macro_rules! make_derives {
+    ($($name:ident),*) => {
+        $(
+            #[proc_macro_derive($name)]
+            pub fn $name(input: TokenStream) -> TokenStream {
+                println!("Derive {}: {}", stringify!($name), input);
+                TokenStream::new()
+            }
+        )*
+    }
+}
+
+make_derives!(First, Second, Third, Fourth, Fifth);
diff --git a/src/test/ui/proc-macro/derive-expand-order.rs b/src/test/ui/proc-macro/derive-expand-order.rs
new file mode 100644
index 00000000000..0cf1ceb91de
--- /dev/null
+++ b/src/test/ui/proc-macro/derive-expand-order.rs
@@ -0,0 +1,14 @@
+// run-pass
+// aux-build:multiple-derives.rs
+
+extern crate multiple_derives;
+
+use multiple_derives::*;
+
+#[derive(First)]
+#[derive(Second)]
+#[derive(Third, Fourth)]
+#[derive(Fifth)]
+pub struct Foo {}
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/derive-expand-order.stdout b/src/test/ui/proc-macro/derive-expand-order.stdout
new file mode 100644
index 00000000000..3ac1adf92c2
--- /dev/null
+++ b/src/test/ui/proc-macro/derive-expand-order.stdout
@@ -0,0 +1,5 @@
+Derive First: #[derive(Second)] #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo { }
+Derive Second: #[derive(Third, Fourth)] #[derive(Fifth)] pub struct Foo { }
+Derive Third: #[derive(Fifth)] pub struct Foo { }
+Derive Fourth: #[derive(Fifth)] pub struct Foo { }
+Derive Fifth: pub struct Foo { }
diff --git a/src/test/ui/proc-macro/issue-36935.stderr b/src/test/ui/proc-macro/issue-36935.stderr
index 2b2e28fdb2f..079e134c6f8 100644
--- a/src/test/ui/proc-macro/issue-36935.stderr
+++ b/src/test/ui/proc-macro/issue-36935.stderr
@@ -1,11 +1,3 @@
-error: proc-macro derive panicked
-  --> $DIR/issue-36935.rs:6:20
-   |
-LL | #[derive(Identity, Panic)]
-   |                    ^^^^^
-   |
-   = help: message: panic-derive
-
 error[E0428]: the name `Baz` is defined multiple times
   --> $DIR/issue-36935.rs:7:1
    |
@@ -17,6 +9,14 @@ LL | struct Baz {
    |
    = note: `Baz` must be defined only once in the type namespace of this module
 
+error: proc-macro derive panicked
+  --> $DIR/issue-36935.rs:6:20
+   |
+LL | #[derive(Identity, Panic)]
+   |                    ^^^^^
+   |
+   = help: message: panic-derive
+
 error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0428`.