From e86c2ba5459679cf264fd2f037e246f1924686ac Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Thu, 26 Jan 2023 13:50:18 -0500 Subject: [PATCH] Don't flatten blocks that have labels --- src/matches.rs | 5 +++-- tests/target/issue_5676.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/target/issue_5676.rs diff --git a/src/matches.rs b/src/matches.rs index fe9e7836ba71..a7677c3a35cd 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -306,8 +306,9 @@ fn block_can_be_flattened<'a>( expr: &'a ast::Expr, ) -> Option<&'a ast::Block> { match expr.kind { - ast::ExprKind::Block(ref block, _) - if !is_unsafe_block(block) + ast::ExprKind::Block(ref block, label) + if label.is_none() + && !is_unsafe_block(block) && !context.inside_macro() && is_simple_block(context, block, Some(&expr.attrs)) && !stmt_is_expr_mac(&block.stmts[0]) => diff --git a/tests/target/issue_5676.rs b/tests/target/issue_5676.rs new file mode 100644 index 000000000000..258771105453 --- /dev/null +++ b/tests/target/issue_5676.rs @@ -0,0 +1,8 @@ +fn main() { + match true { + true => 'a: { + break 'a; + } + _ => (), + } +}