Skip to content

Commit b776c49

Browse files
committed
macros: Do not lower macro definitions to HIR
Avoid lowering block statements that should not be lowered, such as macro-rules definitions
1 parent 14b99be commit b776c49

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

gcc/rust/hir/rust-ast-lower.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
6767

6868
for (auto &s : expr.get_statements ())
6969
{
70+
if (s->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION)
71+
continue;
72+
7073
if (block_did_terminate)
7174
rust_warning_at (s->get_locus (), 0, "unreachable statement");
7275

gcc/testsuite/rust/compile/macro16.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
macro_rules! create_type {
3+
($s:ident) => {
4+
struct $s(i32);
5+
};
6+
}
7+
8+
create_type!(Wrapper);
9+
10+
let _ = Wrapper(15);
11+
}

0 commit comments

Comments
 (0)