]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix expansion of macros inside modules
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 22 Feb 2025 00:07:59 +0000 (19:07 -0500)
committerPhilip Herron <philip.herron@embecosm.com>
Sun, 23 Feb 2025 19:54:11 +0000 (19:54 +0000)
gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Override DefaultASTVisitor in order to
expand a module's items, rather than directly visit them.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Add override.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-expand-module.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h
gcc/testsuite/rust/compile/macros/mbe/macro-expand-module.rs [new file with mode: 0644]

index d1886cab3ba6755f67c40d2b619ded7253c2cf01..b3a53c11f09e5fb2e7fbd27e9061da24bf89d6a6 100644 (file)
@@ -721,6 +721,12 @@ ExpandVisitor::visit (AST::TypeBoundWhereClauseItem &item)
     visit (bound);
 }
 
+void
+ExpandVisitor::visit (AST::Module &module)
+{
+  expand_inner_items (module.get_items ());
+}
+
 void
 ExpandVisitor::visit (AST::ExternCrate &crate)
 {}
index c353689b2c521cb4733682f98527e3f32e075587..131d62f52270bde594f8274733f335cb72884eb7 100644 (file)
@@ -237,6 +237,7 @@ public:
   void visit (AST::TypeParam &param) override;
   void visit (AST::LifetimeWhereClauseItem &) override;
   void visit (AST::TypeBoundWhereClauseItem &item) override;
+  void visit (AST::Module &module) override;
   void visit (AST::ExternCrate &crate) override;
   void visit (AST::UseTreeGlob &) override;
   void visit (AST::UseTreeList &) override;
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-expand-module.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-expand-module.rs
new file mode 100644 (file)
index 0000000..e3e702e
--- /dev/null
@@ -0,0 +1,11 @@
+mod foo {
+    macro_rules! bar {
+        () => ()
+    }
+
+    bar! ();
+
+    pub struct S;
+}
+
+pub fn buzz(_: foo::S) {}