Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas

Avoid deleting labeled blocks

Fix #11575.

changelog: [`unnecessary_operation`]: skip labeled blocks
This commit is contained in:
bors 2024-02-03 22:48:46 +00:00
commit 9fb41079ca
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, _) => {
if block.stmts.is_empty() {
if block.stmts.is_empty() && !block.targeted_by_break {
block.expr.as_ref().and_then(|e| {
match block.rules {
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None,

View File

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