diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-17 10:22:44 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-17 10:22:44 +0100 |
commit | b776c4953ca125855f37e381ad51ae8ae836247c (patch) | |
tree | 0c647ecb8da046bd48fd981803ccf245dc2f73be | |
parent | 14b99bed0801da460db998f8ec65f31e992f0e52 (diff) | |
download | gcc-b776c4953ca125855f37e381ad51ae8ae836247c.zip gcc-b776c4953ca125855f37e381ad51ae8ae836247c.tar.gz gcc-b776c4953ca125855f37e381ad51ae8ae836247c.tar.bz2 |
macros: Do not lower macro definitions to HIR
Avoid lowering block statements that should not be lowered, such as
macro-rules definitions
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro16.rs | 11 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index d9ce9aa..27f73e0 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -67,6 +67,9 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) for (auto &s : expr.get_statements ()) { + if (s->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION) + continue; + if (block_did_terminate) rust_warning_at (s->get_locus (), 0, "unreachable statement"); diff --git a/gcc/testsuite/rust/compile/macro16.rs b/gcc/testsuite/rust/compile/macro16.rs new file mode 100644 index 0000000..e5e56ed --- /dev/null +++ b/gcc/testsuite/rust/compile/macro16.rs @@ -0,0 +1,11 @@ +fn main() { + macro_rules! create_type { + ($s:ident) => { + struct $s(i32); + }; + } + + create_type!(Wrapper); + + let _ = Wrapper(15); +} |