about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-11-02 13:22:03 -0500
committerAaron Hill <aa1ronham@gmail.com>2020-11-02 13:22:03 -0500
commit22383b32b8a79409e5801e0d9c469da71f10ad47 (patch)
treea1dc77754819d76eb4ff2bf79a5fb7f3010c3600 /src
parent499ebcfdf3b09a646154f321b7c28f5105e4dbf7 (diff)
downloadrust-22383b32b8a79409e5801e0d9c469da71f10ad47.tar.gz
rust-22383b32b8a79409e5801e0d9c469da71f10ad47.zip
Use reparsed `TokenStream` if we captured any inner attributes
Fixes #78675

We now bail out of `prepend_attrs` if we ended up capturing any inner
attributes (which can happen in several places, due to token capturing
for `macro_rules!` arguments.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/proc-macro/issue-78675-captured-inner-attrs.rs32
-rw-r--r--src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout86
2 files changed, 118 insertions, 0 deletions
diff --git a/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.rs b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.rs
new file mode 100644
index 00000000000..478809324ee
--- /dev/null
+++ b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.rs
@@ -0,0 +1,32 @@
+// check-pass
+// edition:2018
+// 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;
+
+macro_rules! foo {(
+    #[fake_attr]
+    $item:item
+) => (
+    $item
+)}
+
+macro_rules! outer {($item:item) => (
+    print_bang! { // Identity proc-macro
+        foo! {
+            #[fake_attr]
+            $item
+        }
+    }
+)}
+outer! {
+    mod bar {
+        //! Foo
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout
new file mode 100644
index 00000000000..c4ee44f6541
--- /dev/null
+++ b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout
@@ -0,0 +1,86 @@
+PRINT-BANG INPUT (DISPLAY): foo ! { #[fake_attr] mod bar {
+    #![doc = r" Foo"]
+} }
+PRINT-BANG INPUT (DEBUG): TokenStream [
+    Ident {
+        ident: "foo",
+        span: $DIR/issue-78675-captured-inner-attrs.rs:20:9: 20:12 (#4),
+    },
+    Punct {
+        ch: '!',
+        spacing: Alone,
+        span: $DIR/issue-78675-captured-inner-attrs.rs:20:12: 20:13 (#4),
+    },
+    Group {
+        delimiter: Brace,
+        stream: TokenStream [
+            Punct {
+                ch: '#',
+                spacing: Alone,
+                span: $DIR/issue-78675-captured-inner-attrs.rs:21:13: 21:14 (#4),
+            },
+            Group {
+                delimiter: Bracket,
+                stream: TokenStream [
+                    Ident {
+                        ident: "fake_attr",
+                        span: $DIR/issue-78675-captured-inner-attrs.rs:21:15: 21:24 (#4),
+                    },
+                ],
+                span: $DIR/issue-78675-captured-inner-attrs.rs:21:14: 21:25 (#4),
+            },
+            Group {
+                delimiter: None,
+                stream: TokenStream [
+                    Ident {
+                        ident: "mod",
+                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                    },
+                    Ident {
+                        ident: "bar",
+                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                    },
+                    Group {
+                        delimiter: Brace,
+                        stream: TokenStream [
+                            Punct {
+                                ch: '#',
+                                spacing: Joint,
+                                span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                            },
+                            Punct {
+                                ch: '!',
+                                spacing: Alone,
+                                span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                            },
+                            Group {
+                                delimiter: Bracket,
+                                stream: TokenStream [
+                                    Ident {
+                                        ident: "doc",
+                                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                                    },
+                                    Punct {
+                                        ch: '=',
+                                        spacing: Alone,
+                                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                                    },
+                                    Literal {
+                                        kind: StrRaw(0),
+                                        symbol: " Foo",
+                                        suffix: None,
+                                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                                    },
+                                ],
+                                span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                            },
+                        ],
+                        span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+                    },
+                ],
+                span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),
+            },
+        ],
+        span: $DIR/issue-78675-captured-inner-attrs.rs:20:14: 23:10 (#4),
+    },
+]