@@ -14,7 +14,7 @@ use rustc_infer::infer;
14
14
use rustc_infer:: traits:: { self , StatementAsExpression } ;
15
15
use rustc_middle:: lint:: in_external_macro;
16
16
use rustc_middle:: ty:: {
17
- self , suggest_constraining_type_params, Binder , DefIdTree , IsSuggestable , Ty ,
17
+ self , suggest_constraining_type_params, Binder , DefIdTree , IsSuggestable , ToPredicate , Ty ,
18
18
} ;
19
19
use rustc_session:: errors:: ExprParenthesesNeeded ;
20
20
use rustc_span:: symbol:: sym;
@@ -1278,15 +1278,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1278
1278
&& !results. expr_adjustments ( callee_expr) . iter ( ) . any ( |adj| matches ! ( adj. kind, ty:: adjustment:: Adjust :: Deref ( ..) ) )
1279
1279
// Check that we're in fact trying to clone into the expected type
1280
1280
&& self . can_coerce ( * pointee_ty, expected_ty)
1281
+ && let trait_ref = ty:: Binder :: dummy ( self . tcx . mk_trait_ref ( clone_trait_did, [ expected_ty] ) )
1281
1282
// And the expected type doesn't implement `Clone`
1282
1283
&& !self . predicate_must_hold_considering_regions ( & traits:: Obligation :: new (
1283
1284
self . tcx ,
1284
1285
traits:: ObligationCause :: dummy ( ) ,
1285
1286
self . param_env ,
1286
- ty:: Binder :: dummy ( self . tcx . mk_trait_ref (
1287
- clone_trait_did,
1288
- [ expected_ty] ,
1289
- ) ) ,
1287
+ trait_ref,
1290
1288
) )
1291
1289
{
1292
1290
diag. span_note (
@@ -1305,6 +1303,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1305
1303
diag,
1306
1304
vec ! [ ( param. name. as_str( ) , "Clone" , Some ( clone_trait_did) ) ] . into_iter ( ) ,
1307
1305
) ;
1306
+ } else {
1307
+ self . suggest_derive ( diag, & [ ( trait_ref. to_predicate ( self . tcx ) , None , None ) ] ) ;
1308
1308
}
1309
1309
}
1310
1310
}
0 commit comments