diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index c234e4f9b110..af4d7a92295d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -621,16 +621,14 @@ fn check_if_applicable_to_argument<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'tcx && let ExprKind::MethodCall(method_path, caller, &[], _) = expr.kind && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && let method_name = method_path.ident.name.as_str() - && match method_name { - "to_owned" => cx.tcx.is_diagnostic_item(sym::to_owned_method, method_def_id), - "to_string" => cx.tcx.is_diagnostic_item(sym::to_string_method, method_def_id), - "to_vec" => cx - .tcx - .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).instantiate_identity().is_slice()) - .is_some(), - _ => false, - } + && (cx.tcx.is_diagnostic_item(sym::to_owned_method, method_def_id) + || cx.tcx.is_diagnostic_item(sym::to_string_method, method_def_id) + || ( + method_name == "to_vec" && + cx.tcx.impl_of_method(method_def_id).filter(|&impl_did| { + cx.tcx.type_of(impl_did).instantiate_identity().is_slice() + }) + .is_some())) && let original_arg_ty = cx.typeck_results().node_type(caller.hir_id).peel_refs() && let arg_ty = cx.typeck_results().expr_ty(arg) && let ty::Ref(_, arg_ty, Mutability::Not) = arg_ty.kind()