Skip to content

Commit 998a311

Browse files
committed
[redundant_guards]: lint empty slice checks
1 parent ef587d2 commit 998a311

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clippy_lints/src/matches/redundant_guards.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,17 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
106106
&& let Some(binding) = get_pat_binding(cx, recv, outer_arm)
107107
{
108108
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
109+
let slice_like = ty.is_slice() || ty.is_array();
109110

110-
if path.ident.name == sym!(is_empty) && ty.is_str() {
111+
if path.ident.name == sym!(is_empty) {
111112
// `s if s.is_empty()` becomes ""
113+
// `arr if arr.is_empty()` becomes []
112114

113-
emit_redundant_guards(cx, outer_arm, if_expr.span, r#""""#.into(), &binding, None)
115+
if ty.is_str() {
116+
emit_redundant_guards(cx, outer_arm, if_expr.span, r#""""#.into(), &binding, None)
117+
} else if slice_like {
118+
emit_redundant_guards(cx, outer_arm, if_expr.span, "[]".into(), &binding, None)
119+
}
114120
}
115121
}
116122
}

0 commit comments

Comments
 (0)