Skip to content

Commit c3a707a

Browse files
powerboat9philberty
authored andcommitted
Fix expansion of macros inside modules
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 <[email protected]>
1 parent 5c67579 commit c3a707a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

gcc/rust/expand/rust-expand-visitor.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@ ExpandVisitor::visit (AST::TypeBoundWhereClauseItem &item)
721721
visit (bound);
722722
}
723723

724+
void
725+
ExpandVisitor::visit (AST::Module &module)
726+
{
727+
expand_inner_items (module.get_items ());
728+
}
729+
724730
void
725731
ExpandVisitor::visit (AST::ExternCrate &crate)
726732
{}

gcc/rust/expand/rust-expand-visitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class ExpandVisitor : public AST::DefaultASTVisitor
237237
void visit (AST::TypeParam &param) override;
238238
void visit (AST::LifetimeWhereClauseItem &) override;
239239
void visit (AST::TypeBoundWhereClauseItem &item) override;
240+
void visit (AST::Module &module) override;
240241
void visit (AST::ExternCrate &crate) override;
241242
void visit (AST::UseTreeGlob &) override;
242243
void visit (AST::UseTreeList &) override;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mod foo {
2+
macro_rules! bar {
3+
() => ()
4+
}
5+
6+
bar! ();
7+
8+
pub struct S;
9+
}
10+
11+
pub fn buzz(_: foo::S) {}

0 commit comments

Comments
 (0)