From 6275e77e6a273144558ce06c862821d330958952 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 30 Nov 2023 17:45:04 +0100 Subject: [PATCH] Do not check twice whether `qpath` is a `QPath::TypeRelative` variant --- clippy_lints/src/manual_string_new.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/manual_string_new.rs b/clippy_lints/src/manual_string_new.rs index 737c70496c2bd..781db4b97f083 100644 --- a/clippy_lints/src/manual_string_new.rs +++ b/clippy_lints/src/manual_string_new.rs @@ -108,18 +108,16 @@ fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, args: &[Expr<'_ let arg_kind = &args[0].kind; if let ExprKind::Path(qpath) = &func.kind { - if let QPath::TypeRelative(_, _) = qpath { - // String::from(...) or String::try_from(...) - if let QPath::TypeRelative(ty, path_seg) = qpath - && [sym::from, sym::try_from].contains(&path_seg.ident.name) - && let TyKind::Path(qpath) = &ty.kind - && let QPath::Resolved(_, path) = qpath - && let [path_seg] = path.segments - && path_seg.ident.name == sym::String - && is_expr_kind_empty_str(arg_kind) - { - warn_then_suggest(cx, span); - } + // String::from(...) or String::try_from(...) + if let QPath::TypeRelative(ty, path_seg) = qpath + && [sym::from, sym::try_from].contains(&path_seg.ident.name) + && let TyKind::Path(qpath) = &ty.kind + && let QPath::Resolved(_, path) = qpath + && let [path_seg] = path.segments + && path_seg.ident.name == sym::String + && is_expr_kind_empty_str(arg_kind) + { + warn_then_suggest(cx, span); } else if let QPath::Resolved(_, path) = qpath { // From::from(...) or TryFrom::try_from(...) if let [path_seg1, path_seg2] = path.segments