Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
if let ExprKind::Let(lt) = expr.kind
&& match lt.pat.kind {
PatKind::Slice([], None, []) => true,
PatKind::Expr(lit) => match lit.kind {
PatExprKind::Lit { lit, .. } => match lit.node {
LitKind::Str(lit, _) => lit.as_str().is_empty(),
_ => false,
},
_ => false,
PatKind::Expr(lit)
if let PatExprKind::Lit { lit, .. } = lit.kind
&& let LitKind::Str(lit, _) = lit.node =>
{
lit.as_str().is_empty()
},
_ => false,
}
Expand Down Expand Up @@ -336,33 +335,23 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
}

fn is_first_generic_integral<'tcx>(segment: &'tcx PathSegment<'tcx>) -> bool {
if let Some(generic_args) = segment.args {
if generic_args.args.is_empty() {
return false;
}
let arg = &generic_args.args[0];
if let GenericArg::Type(rustc_hir::Ty {
kind: TyKind::Path(QPath::Resolved(_, path)),
..
}) = arg
{
let segments = &path.segments;
let segment = &segments[0];
let res = &segment.res;
if matches!(res, Res::PrimTy(PrimTy::Uint(_))) || matches!(res, Res::PrimTy(PrimTy::Int(_))) {
return true;
}
}
if let Some(generic_args) = segment.args
&& let [GenericArg::Type(ty), ..] = &generic_args.args
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
&& let [segment, ..] = &path.segments
&& matches!(segment.res, Res::PrimTy(PrimTy::Uint(_) | PrimTy::Int(_)))
{
true
} else {
false
}

false
}

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

if matches!(res, Res::PrimTy(PrimTy::Uint(_))) || matches!(res, Res::PrimTy(PrimTy::Int(_))) {
if matches!(res, Res::PrimTy(PrimTy::Uint(_) | PrimTy::Int(_))) {
return Some(LenOutput::Integral);
}

Expand Down