Apply suggestions from code review

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
This commit is contained in:
Yukang 2023-01-06 15:03:05 +08:00 committed by yukang
parent e7a777805a
commit 1a0a6132a8

View File

@ -1021,25 +1021,26 @@ pub(crate) fn suggest_clone_for_ref(
expr_ty: Ty<'tcx>, expr_ty: Ty<'tcx>,
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,
) -> bool { ) -> bool {
if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind() && if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind()
let Some(clone_trait_def) = self.tcx.lang_items().clone_trait() && && let Some(clone_trait_def) = self.tcx.lang_items().clone_trait()
expected_ty == *inner_ty && && expected_ty == *inner_ty
self && self
.infcx .infcx
.type_implements_trait( .type_implements_trait(
clone_trait_def, clone_trait_def,
[self.tcx.erase_regions(expected_ty)], [self.tcx.erase_regions(expected_ty)],
self.param_env self.param_env
) )
.must_apply_modulo_regions() { .must_apply_modulo_regions()
diag.span_suggestion_verbose( {
expr.span.shrink_to_hi(), diag.span_suggestion_verbose(
"consider using clone here", expr.span.shrink_to_hi(),
".clone()", "consider using clone here",
Applicability::MachineApplicable, ".clone()",
); Applicability::MachineApplicable,
return true; );
} return true;
}
false false
} }