Skip to content

Commit 9fb4107

Browse files
committedFeb 3, 2024
Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas
Avoid deleting labeled blocks Fix #11575. changelog: [`unnecessary_operation`]: skip labeled blocks
2 parents c82162e + abced20 commit 9fb4107

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

Diff for: ‎clippy_lints/src/no_effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
357357
}
358358
},
359359
ExprKind::Block(block, _) => {
360-
if block.stmts.is_empty() {
360+
if block.stmts.is_empty() && !block.targeted_by_break {
361361
block.expr.as_ref().and_then(|e| {
362362
match block.rules {
363363
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => None,

Diff for: ‎tests/ui/unnecessary_operation.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,11 @@ fn main() {
106106

107107
// Issue #11885
108108
Cout << 16;
109+
110+
// Issue #11575
111+
// Bad formatting is required to trigger the bug
112+
#[rustfmt::skip]
113+
'label: {
114+
break 'label
115+
};
109116
}

Diff for: ‎tests/ui/unnecessary_operation.rs

+7
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,11 @@ fn main() {
110110

111111
// Issue #11885
112112
Cout << 16;
113+
114+
// Issue #11575
115+
// Bad formatting is required to trigger the bug
116+
#[rustfmt::skip]
117+
'label: {
118+
break 'label
119+
};
113120
}

0 commit comments

Comments
 (0)