@@ -1121,36 +1121,23 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1121
1121
let Some ( generics) = self . tcx . hir ( ) . get_generics ( owner. def_id ) else { return false } ;
1122
1122
let ty:: Ref ( _, inner_ty, hir:: Mutability :: Not ) = ty. kind ( ) else { return false } ;
1123
1123
let ty:: Param ( param) = inner_ty. kind ( ) else { return false } ;
1124
- let Some ( generic_param) = generics. get_named ( param. name ) else { return false } ;
1125
1124
let ObligationCauseCode :: FunctionArgumentObligation { arg_hir_id, .. } = obligation. cause . code ( ) else { return false } ;
1126
1125
let arg_node = self . tcx . hir ( ) . get ( * arg_hir_id) ;
1127
1126
let Node :: Expr ( Expr { kind : hir:: ExprKind :: Path ( _) , ..} ) = arg_node else { return false } ;
1128
1127
1129
1128
let clone_trait = self . tcx . require_lang_item ( LangItem :: Clone , None ) ;
1130
- let has_clone = self
1131
- . type_implements_trait ( clone_trait, [ ty] , obligation. param_env )
1132
- . must_apply_modulo_regions ( ) ;
1129
+ let has_clone = |ty| {
1130
+ self . type_implements_trait ( clone_trait, [ ty] , obligation. param_env )
1131
+ . must_apply_modulo_regions ( )
1132
+ } ;
1133
1133
1134
- let trait_pred_and_suggested_ty =
1135
- trait_pred. map_bound ( |trait_pred| ( trait_pred, * inner_ty) ) ;
1136
1134
let new_obligation = self . mk_trait_obligation_with_new_self_ty (
1137
1135
obligation. param_env ,
1138
- trait_pred_and_suggested_ty ,
1136
+ trait_pred . map_bound ( |trait_pred| ( trait_pred , * inner_ty ) ) ,
1139
1137
) ;
1140
1138
1141
- if has_clone && self . predicate_may_hold ( & new_obligation) {
1142
- let clone_bound = generics
1143
- . bounds_for_param ( generic_param. def_id )
1144
- . flat_map ( |bp| bp. bounds )
1145
- . any ( |bound| {
1146
- if let hir:: GenericBound :: Trait ( hir:: PolyTraitRef { trait_ref, .. } , ..) = bound
1147
- {
1148
- Some ( clone_trait) == trait_ref. trait_def_id ( )
1149
- } else {
1150
- false
1151
- }
1152
- } ) ;
1153
- if !clone_bound {
1139
+ if self . predicate_may_hold ( & new_obligation) && has_clone ( ty) {
1140
+ if !has_clone ( param. to_ty ( self . tcx ) ) {
1154
1141
suggest_constraining_type_param (
1155
1142
self . tcx ,
1156
1143
generics,
0 commit comments