about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-03 22:48:46 +0000
committerbors <bors@rust-lang.org>2024-02-03 22:48:46 +0000
commit9fb41079ca03a68e1ffc63d82643eb0afe68d3a1 (patch)
treeec96e8549d3b03443804ee74031ec54b0ad89fb5
parentc82162eb71212b54eb851dae8b206de9ccd61471 (diff)
parentabced206d7b9f07f39c1324913f498851e948799 (diff)
downloadrust-9fb41079ca03a68e1ffc63d82643eb0afe68d3a1.tar.gz
rust-9fb41079ca03a68e1ffc63d82643eb0afe68d3a1.zip
Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas
Avoid deleting labeled blocks

Fix #11575.

changelog: [`unnecessary_operation`]: skip labeled blocks
-rw-r--r--clippy_lints/src/no_effect.rs2
-rw-r--r--tests/ui/unnecessary_operation.fixed7
-rw-r--r--tests/ui/unnecessary_operation.rs7
3 files changed, 15 insertions, 1 deletions
diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs
index 0d234f7f9b5..580160efeb7 100644
--- a/clippy_lints/src/no_effect.rs
+++ b/clippy_lints/src/no_effect.rs
@@ -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,
diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed
index 463412daec0..11761c6c90e 100644
--- a/tests/ui/unnecessary_operation.fixed
+++ b/tests/ui/unnecessary_operation.fixed
@@ -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
+    };
 }
diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs
index f0d28e28902..de0081289ac 100644
--- a/tests/ui/unnecessary_operation.rs
+++ b/tests/ui/unnecessary_operation.rs
@@ -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
+    };
 }