about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-08-14 03:29:51 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-08-14 03:39:32 +0200
commit8f472e8b5c0923a36a3cd90c3d5fc990943dd034 (patch)
tree23499dc39551f6ed7647d400bca66def56f86f2f
parent577166503aee7290e09374da21f4045c455acfd5 (diff)
downloadrust-8f472e8b5c0923a36a3cd90c3d5fc990943dd034.tar.gz
rust-8f472e8b5c0923a36a3cd90c3d5fc990943dd034.zip
Add regression test for a former ICE involving helper attributes containing interpolated tokens
Co-authored-by: Jana Dönszelmann <jana@donsz.nl>
-rw-r--r--tests/ui/attributes/auxiliary/derive_macro_with_helper.rs8
-rw-r--r--tests/ui/attributes/helper-attr-interpolated-non-lit-arg.rs20
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/attributes/auxiliary/derive_macro_with_helper.rs b/tests/ui/attributes/auxiliary/derive_macro_with_helper.rs
new file mode 100644
index 00000000000..128af50ce36
--- /dev/null
+++ b/tests/ui/attributes/auxiliary/derive_macro_with_helper.rs
@@ -0,0 +1,8 @@
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(Derive, attributes(arg))]
+pub fn derive(_: TokenStream) -> TokenStream {
+    TokenStream::new()
+}
diff --git a/tests/ui/attributes/helper-attr-interpolated-non-lit-arg.rs b/tests/ui/attributes/helper-attr-interpolated-non-lit-arg.rs
new file mode 100644
index 00000000000..17c9ad1bd48
--- /dev/null
+++ b/tests/ui/attributes/helper-attr-interpolated-non-lit-arg.rs
@@ -0,0 +1,20 @@
+// Regression test for <https://github.com/rust-lang/rust/issues/140612>.
+//@ proc-macro: derive_macro_with_helper.rs
+//@ edition: 2018
+//@ check-pass
+
+macro_rules! expand {
+    ($text:expr) => {
+        #[derive(derive_macro_with_helper::Derive)]
+        // This inert attr is completely valid because it follows the grammar
+        // `#` `[` SimplePath DelimitedTokenStream `]`.
+        // However, we used to incorrectly delay a bug here and ICE when trying to parse `$text` as
+        // the inside of a "meta item list" which may only begin with literals or paths.
+        #[arg($text)]
+        pub struct Foo;
+    };
+}
+
+expand!(1 + 1);
+
+fn main() {}