Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 21, 2024
1 parent 635acb6 commit eaa0710
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions clippy_lints/src/methods/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit eaa0710

Please sign in to comment.