about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJana Dönszelmann <jana@donsz.nl>2025-02-26 14:29:19 +0100
committerJana Dönszelmann <jana@donsz.nl>2025-02-28 09:43:46 +0100
commit41dd80aeaa706c169df62bdf16033b61b914cb87 (patch)
tree695dbc7c2abfb88fccd58453a8e8cc9e3db14cd8
parent96cfc75584359ae7ad11cc45968059f29e7b44b7 (diff)
downloadrust-41dd80aeaa706c169df62bdf16033b61b914cb87.tar.gz
rust-41dd80aeaa706c169df62bdf16033b61b914cb87.zip
add test to reproduce #137662 (using ty decl macro fragment in an attr) and fix it
-rw-r--r--compiler/rustc_attr_parsing/src/parser.rs9
-rw-r--r--tests/ui/attributes/decl_macro_ty_in_attr_macro.rs20
2 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs
index b6d66af4466..6c2448b7512 100644
--- a/compiler/rustc_attr_parsing/src/parser.rs
+++ b/compiler/rustc_attr_parsing/src/parser.rs
@@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> {
         {
             self.inside_delimiters.next();
             return Some(MetaItemOrLitParser::Lit(lit));
+        } else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) =
+            self.inside_delimiters.peek()
+        {
+            self.inside_delimiters.next();
+            return MetaItemListParserContext {
+                inside_delimiters: inner_tokens.iter().peekable(),
+                dcx: self.dcx,
+            }
+            .next();
         }
 
         // or a path.
diff --git a/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs b/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs
new file mode 100644
index 00000000000..e633c08be3a
--- /dev/null
+++ b/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs
@@ -0,0 +1,20 @@
+// tests for #137662: using a ty or (or most other) fragment inside an attr macro wouldn't work
+// because of a missing code path. With $repr: tt it did work.
+//@ check-pass
+
+macro_rules! foo {
+    {
+        $repr:ty
+    } => {
+        #[repr($repr)]
+        pub enum Foo {
+            Bar = 0i32,
+        }
+    }
+}
+
+foo! {
+    i32
+}
+
+fn main() {}