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,17 +1021,18 @@ pub(crate) fn suggest_clone_for_ref(
expr_ty: Ty<'tcx>,
expected_ty: Ty<'tcx>,
) -> bool {
if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind() &&
let Some(clone_trait_def) = self.tcx.lang_items().clone_trait() &&
expected_ty == *inner_ty &&
self
if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind()
&& let Some(clone_trait_def) = self.tcx.lang_items().clone_trait()
&& expected_ty == *inner_ty
&& self
.infcx
.type_implements_trait(
clone_trait_def,
[self.tcx.erase_regions(expected_ty)],
self.param_env
)
.must_apply_modulo_regions() {
.must_apply_modulo_regions()
{
diag.span_suggestion_verbose(
expr.span.shrink_to_hi(),
"consider using clone here",