Skip to content

Commit

Permalink
Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas
Browse files Browse the repository at this point in the history
Avoid deleting labeled blocks

Fix #11575.

changelog: [`unnecessary_operation`]: skip labeled blocks
  • Loading branch information
bors committed Feb 3, 2024
2 parents c82162e + abced20 commit 9fb4107
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/unnecessary_operation.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
7 changes: 7 additions & 0 deletions tests/ui/unnecessary_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

0 comments on commit 9fb4107

Please sign in to comment.