@@ -1121,36 +1121,23 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11211121 let Some ( generics) = self . tcx . hir ( ) . get_generics ( owner. def_id ) else { return false } ;
11221122 let ty:: Ref ( _, inner_ty, hir:: Mutability :: Not ) = ty. kind ( ) else { return false } ;
11231123 let ty:: Param ( param) = inner_ty. kind ( ) else { return false } ;
1124- let Some ( generic_param) = generics. get_named ( param. name ) else { return false } ;
11251124 let ObligationCauseCode :: FunctionArgumentObligation { arg_hir_id, .. } = obligation. cause . code ( ) else { return false } ;
11261125 let arg_node = self . tcx . hir ( ) . get ( * arg_hir_id) ;
11271126 let Node :: Expr ( Expr { kind : hir:: ExprKind :: Path ( _) , ..} ) = arg_node else { return false } ;
11281127
11291128 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+ } ;
11331133
1134- let trait_pred_and_suggested_ty =
1135- trait_pred. map_bound ( |trait_pred| ( trait_pred, * inner_ty) ) ;
11361134 let new_obligation = self . mk_trait_obligation_with_new_self_ty (
11371135 obligation. param_env ,
1138- trait_pred_and_suggested_ty ,
1136+ trait_pred . map_bound ( |trait_pred| ( trait_pred , * inner_ty ) ) ,
11391137 ) ;
11401138
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 ) ) {
11541141 suggest_constraining_type_param (
11551142 self . tcx ,
11561143 generics,
0 commit comments