Skip to content

Commit

Permalink
Avoid deleting labeled blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn authored and blyxyas committed Feb 3, 2024
1 parent b58b88c commit abced20
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 abced20

Please sign in to comment.