Skip to content

Commit 1954d4c

Browse files
authored
len_zero: clean-up a bit (#15518)
changelog: none
2 parents 0039c64 + f177835 commit 1954d4c

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
176176
if let ExprKind::Let(lt) = expr.kind
177177
&& match lt.pat.kind {
178178
PatKind::Slice([], None, []) => true,
179-
PatKind::Expr(lit) => match lit.kind {
180-
PatExprKind::Lit { lit, .. } => match lit.node {
181-
LitKind::Str(lit, _) => lit.as_str().is_empty(),
182-
_ => false,
183-
},
184-
_ => false,
179+
PatKind::Expr(lit)
180+
if let PatExprKind::Lit { lit, .. } = lit.kind
181+
&& let LitKind::Str(lit, _) = lit.node =>
182+
{
183+
lit.as_str().is_empty()
185184
},
186185
_ => false,
187186
}
@@ -336,33 +335,23 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
336335
}
337336

338337
fn is_first_generic_integral<'tcx>(segment: &'tcx PathSegment<'tcx>) -> bool {
339-
if let Some(generic_args) = segment.args {
340-
if generic_args.args.is_empty() {
341-
return false;
342-
}
343-
let arg = &generic_args.args[0];
344-
if let GenericArg::Type(rustc_hir::Ty {
345-
kind: TyKind::Path(QPath::Resolved(_, path)),
346-
..
347-
}) = arg
348-
{
349-
let segments = &path.segments;
350-
let segment = &segments[0];
351-
let res = &segment.res;
352-
if matches!(res, Res::PrimTy(PrimTy::Uint(_))) || matches!(res, Res::PrimTy(PrimTy::Int(_))) {
353-
return true;
354-
}
355-
}
338+
if let Some(generic_args) = segment.args
339+
&& let [GenericArg::Type(ty), ..] = &generic_args.args
340+
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
341+
&& let [segment, ..] = &path.segments
342+
&& matches!(segment.res, Res::PrimTy(PrimTy::Uint(_) | PrimTy::Int(_)))
343+
{
344+
true
345+
} else {
346+
false
356347
}
357-
358-
false
359348
}
360349

361350
fn parse_len_output<'tcx>(cx: &LateContext<'tcx>, sig: FnSig<'tcx>) -> Option<LenOutput> {
362351
if let Some(segment) = extract_future_output(cx, sig.output()) {
363352
let res = segment.res;
364353

365-
if matches!(res, Res::PrimTy(PrimTy::Uint(_))) || matches!(res, Res::PrimTy(PrimTy::Int(_))) {
354+
if matches!(res, Res::PrimTy(PrimTy::Uint(_) | PrimTy::Int(_))) {
366355
return Some(LenOutput::Integral);
367356
}
368357

0 commit comments

Comments
 (0)