Avoid deleting labeled blocks

This commit is contained in:
Seo Sanghyeon 2024-02-01 06:09:55 +09:00 committed by blyxyas
parent b58b88c966
commit abced206d7
No known key found for this signature in database
GPG key ID: 9698805551971573
3 changed files with 15 additions and 1 deletions

View file

@ -357,7 +357,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
} }
}, },
ExprKind::Block(block, _) => { ExprKind::Block(block, _) => {
if block.stmts.is_empty() { if block.stmts.is_empty() && !block.targeted_by_break {
block.expr.as_ref().and_then(|e| { block.expr.as_ref().and_then(|e| {
match block.rules { match block.rules {
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None, BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None,

View file

@ -106,4 +106,11 @@ fn main() {
// Issue #11885 // Issue #11885
Cout << 16; Cout << 16;
// Issue #11575
// Bad formatting is required to trigger the bug
#[rustfmt::skip]
'label: {
break 'label
};
} }

View file

@ -110,4 +110,11 @@ fn main() {
// Issue #11885 // Issue #11885
Cout << 16; Cout << 16;
// Issue #11575
// Bad formatting is required to trigger the bug
#[rustfmt::skip]
'label: {
break 'label
};
} }