about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/unused.rs
diff options
context:
space:
mode:
authorsurechen <chenshuo17@huawei.com>2024-11-14 09:08:56 +0800
committersurechen <chenshuo17@huawei.com>2024-11-14 09:08:56 +0800
commit3a74bce72ecbd13065aa544d49b5856010d9f814 (patch)
tree518dd8310ece52e688645f687ecf5ce9517be791 /compiler/rustc_lint/src/unused.rs
parent33d3c27d38df5af198ecb9ace7546cab37818dc5 (diff)
downloadrust-3a74bce72ecbd13065aa544d49b5856010d9f814.tar.gz
rust-3a74bce72ecbd13065aa544d49b5856010d9f814.zip
Adding `BreakValue` to UnusedDelimsCtx to make `UnusedParens` and `UnusedBraces` checking `break`
Diffstat (limited to 'compiler/rustc_lint/src/unused.rs')
-rw-r--r--compiler/rustc_lint/src/unused.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 52126afcf5a..6c13127b04e 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -584,6 +584,7 @@ enum UnusedDelimsCtx {
     MatchScrutineeExpr,
     ReturnValue,
     BlockRetValue,
+    BreakValue,
     LetScrutineeExpr,
     ArrayLenExpr,
     AnonConst,
@@ -605,6 +606,7 @@ impl From<UnusedDelimsCtx> for &'static str {
             UnusedDelimsCtx::MatchScrutineeExpr => "`match` scrutinee expression",
             UnusedDelimsCtx::ReturnValue => "`return` value",
             UnusedDelimsCtx::BlockRetValue => "block return value",
+            UnusedDelimsCtx::BreakValue => "`break` value",
             UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
             UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
             UnusedDelimsCtx::MatchArmExpr => "match arm expression",
@@ -913,6 +915,10 @@ trait UnusedDelimLint {
                 (value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
             }
 
+            Break(_, Some(ref value)) => {
+                (value, UnusedDelimsCtx::BreakValue, false, None, None, true)
+            }
+
             Index(_, ref value, _) => (value, UnusedDelimsCtx::IndexExpr, false, None, None, false),
 
             Assign(_, ref value, _) | AssignOp(.., ref value) => {
@@ -1063,7 +1069,8 @@ impl UnusedDelimLint for UnusedParens {
                                 _,
                                 _,
                             ) if node.is_lazy()))
-                    && !(ctx == UnusedDelimsCtx::ReturnValue
+                    && !((ctx == UnusedDelimsCtx::ReturnValue
+                        || ctx == UnusedDelimsCtx::BreakValue)
                         && matches!(inner.kind, ast::ExprKind::Assign(_, _, _)))
                 {
                     self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)