Skip to content

Commit 406133a

Browse files
committed
refactor it
1 parent 9995434 commit 406133a

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
2-
use clippy_utils::higher::{IfOrIfLetInChain, LetChain};
32
use clippy_utils::source::snippet_with_context;
43
use clippy_utils::{get_item_name, get_parent_as_impl, is_lint_allowed, peel_ref_operators, sugg::Sugg};
54
use if_chain::if_chain;
@@ -169,37 +168,29 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
169168
return;
170169
}
171170

172-
if let Some(let_chain) = LetChain::hir(expr) {
173-
for if_let in let_chain.conds.iter().filter_map(|cond| {
174-
if let IfOrIfLetInChain::IfLet(if_let) = cond {
175-
return Some(if_let);
176-
}
177-
None
178-
}) {
179-
if has_is_empty(cx, if_let.let_expr)
180-
&& match if_let.let_pat.kind {
181-
PatKind::Slice([], _, []) => true,
182-
PatKind::Lit(lit) if is_empty_string(lit) => true,
183-
_ => false,
184-
}
185-
{
186-
let mut applicability = Applicability::MachineApplicable;
187-
188-
let lit1 = peel_ref_operators(cx, if_let.let_expr);
189-
let lit_str =
190-
Sugg::hir_with_context(cx, lit1, if_let.let_span.ctxt(), "_", &mut applicability).maybe_par();
191-
192-
span_lint_and_sugg(
193-
cx,
194-
COMPARISON_TO_EMPTY,
195-
if_let.let_span,
196-
"comparison to empty slice using `if let`",
197-
"using `is_empty` is clearer and more explicit",
198-
format!("{lit_str}.is_empty()"),
199-
applicability,
200-
);
201-
}
171+
if let ExprKind::Let(lt) = expr.kind
172+
&& has_is_empty(cx, lt.init)
173+
&& match lt.pat.kind {
174+
PatKind::Slice([], _, []) => true,
175+
PatKind::Lit(lit) if is_empty_string(lit) => true,
176+
_ => false,
202177
}
178+
{
179+
let mut applicability = Applicability::MachineApplicable;
180+
181+
let lit1 = peel_ref_operators(cx, lt.init);
182+
let lit_str =
183+
Sugg::hir_with_context(cx, lit1, lt.span.ctxt(), "_", &mut applicability).maybe_par();
184+
185+
span_lint_and_sugg(
186+
cx,
187+
COMPARISON_TO_EMPTY,
188+
lt.span,
189+
"comparison to empty slice using `if let`",
190+
"using `is_empty` is clearer and more explicit",
191+
format!("{lit_str}.is_empty()"),
192+
applicability,
193+
);
203194
}
204195

205196
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind {

0 commit comments

Comments
 (0)