]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix expansion of macros inside modules
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 22 Feb 2025 00:07:59 +0000 (19:07 -0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:07:09 +0000 (13:07 +0100)
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 8ba9a15fddf4e38ee2291d0aab22c7ee1e6329db..2830d200f72dafd94eb1384e17a1440d61eececb 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 5fc1011e001927ad0446f78afd971b1904aa8cda..ad237c07c2f4e542f8a938e1b359d61e553d459d 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) {}