diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-attribute-visitor.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro42.rs | 31 |
2 files changed, 43 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index e420d09..842fbdf 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -1630,6 +1630,9 @@ AttrVisitor::visit (AST::IfExpr &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1657,6 +1660,9 @@ AttrVisitor::visit (AST::IfExprConseqElse &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1692,6 +1698,9 @@ AttrVisitor::visit (AST::IfExprConseqIf &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1727,6 +1736,9 @@ AttrVisitor::visit (AST::IfExprConseqIfLet &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); condition_expr->accept_vis (*this); + auto cond_fragment = expander.take_expanded_fragment (*this); + if (cond_fragment.should_expand ()) + condition_expr = cond_fragment.take_expression_fragment (); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " diff --git a/gcc/testsuite/rust/compile/macro42.rs b/gcc/testsuite/rust/compile/macro42.rs new file mode 100644 index 0000000..29fa651 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro42.rs @@ -0,0 +1,31 @@ +// { dg-additional-options "-w -frust-cfg=A" } +macro_rules! cfg { + () => {{}}; +} + +fn main() -> i32 { + let mut res = 0; + if cfg!(A) { + res = 1; + } + + if cfg!(A) { + res = 2; + } else { + res = 3; + } + + if cfg!(A) { + res = 4; + } else if cfg!(A) { + res = 5; + } + + let res = if cfg!(A) { + 6 + } else { + 7 + }; + + return res; +} |