Skip to content

Commit eaa0710

Browse files
Improve code readability
1 parent 635acb6 commit eaa0710

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,14 @@ fn check_if_applicable_to_argument<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'tcx
621621
&& let ExprKind::MethodCall(method_path, caller, &[], _) = expr.kind
622622
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
623623
&& let method_name = method_path.ident.name.as_str()
624-
&& match method_name {
625-
"to_owned" => cx.tcx.is_diagnostic_item(sym::to_owned_method, method_def_id),
626-
"to_string" => cx.tcx.is_diagnostic_item(sym::to_string_method, method_def_id),
627-
"to_vec" => cx
628-
.tcx
629-
.impl_of_method(method_def_id)
630-
.filter(|&impl_did| cx.tcx.type_of(impl_did).instantiate_identity().is_slice())
631-
.is_some(),
632-
_ => false,
633-
}
624+
&& (cx.tcx.is_diagnostic_item(sym::to_owned_method, method_def_id)
625+
|| cx.tcx.is_diagnostic_item(sym::to_string_method, method_def_id)
626+
|| (
627+
method_name == "to_vec" &&
628+
cx.tcx.impl_of_method(method_def_id).filter(|&impl_did| {
629+
cx.tcx.type_of(impl_did).instantiate_identity().is_slice()
630+
})
631+
.is_some()))
634632
&& let original_arg_ty = cx.typeck_results().node_type(caller.hir_id).peel_refs()
635633
&& let arg_ty = cx.typeck_results().expr_ty(arg)
636634
&& let ty::Ref(_, arg_ty, Mutability::Not) = arg_ty.kind()

0 commit comments

Comments
 (0)