about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-11-15 19:37:36 +0100
committery21 <30553356+y21@users.noreply.github.com>2023-11-15 19:37:36 +0100
commit998a311a131068ea6d4c42ab21d076b0f386929d (patch)
tree1913fdda3333b2bdf8073ce6f1cec5693241650d
parentef587d22a403ee5d637625d1ccf157efd6402ac3 (diff)
downloadrust-998a311a131068ea6d4c42ab21d076b0f386929d.tar.gz
rust-998a311a131068ea6d4c42ab21d076b0f386929d.zip
[`redundant_guards`]: lint empty slice checks
-rw-r--r--clippy_lints/src/matches/redundant_guards.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs
index 9cc546de22e..9133e785af0 100644
--- a/clippy_lints/src/matches/redundant_guards.rs
+++ b/clippy_lints/src/matches/redundant_guards.rs
@@ -106,11 +106,17 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
             && let Some(binding) = get_pat_binding(cx, recv, outer_arm)
         {
             let ty = cx.typeck_results().expr_ty(recv).peel_refs();
+            let slice_like = ty.is_slice() || ty.is_array();
 
-            if path.ident.name == sym!(is_empty) && ty.is_str() {
+            if path.ident.name == sym!(is_empty) {
                 // `s if s.is_empty()` becomes ""
+                // `arr if arr.is_empty()` becomes []
 
-                emit_redundant_guards(cx, outer_arm, if_expr.span, r#""""#.into(), &binding, None)
+                if ty.is_str() {
+                    emit_redundant_guards(cx, outer_arm, if_expr.span, r#""""#.into(), &binding, None)
+                } else if slice_like {
+                    emit_redundant_guards(cx, outer_arm, if_expr.span, "[]".into(), &binding, None)
+                }
             }
         }
     }