about summary refs log tree commit diff
path: root/tests/ui/macros/macro-rules-attr-nested.rs
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2025-07-28 15:28:20 -0700
committerJosh Triplett <josh@joshtriplett.org>2025-08-08 11:01:12 -0700
commit489734cd08599df822c87d27a38f972413dc13ab (patch)
tree50a7283ab3fcccf45838197745b3684c7cadc85f /tests/ui/macros/macro-rules-attr-nested.rs
parent9a9ccc0edbf50428d0f12441cf50f32d5ea0f558 (diff)
downloadrust-489734cd08599df822c87d27a38f972413dc13ab.tar.gz
rust-489734cd08599df822c87d27a38f972413dc13ab.zip
mbe: Add a test confirming that a macro attribute can apply itself recursively
This allows a macro attribute to implement default arguments by
reapplying itself with the defaults filled in, for instance.
Diffstat (limited to 'tests/ui/macros/macro-rules-attr-nested.rs')
-rw-r--r--tests/ui/macros/macro-rules-attr-nested.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/macros/macro-rules-attr-nested.rs b/tests/ui/macros/macro-rules-attr-nested.rs
new file mode 100644
index 00000000000..af5c30f00dd
--- /dev/null
+++ b/tests/ui/macros/macro-rules-attr-nested.rs
@@ -0,0 +1,24 @@
+//@ run-pass
+//@ check-run-results
+#![feature(macro_attr)]
+
+macro_rules! nest {
+    attr() { struct $name:ident; } => {
+        println!("nest");
+        #[nest(1)]
+        struct $name;
+    };
+    attr(1) { struct $name:ident; } => {
+        println!("nest(1)");
+        #[nest(2)]
+        struct $name;
+    };
+    attr(2) { struct $name:ident; } => {
+        println!("nest(2)");
+    };
+}
+
+fn main() {
+    #[nest]
+    struct S;
+}