@@ -720,28 +720,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
720720
721721 fn suggest_cloning ( & self , err : & mut Diagnostic , ty : Ty < ' tcx > , span : Span ) {
722722 let tcx = self . infcx . tcx ;
723-
724723 // Try to find predicates on *generic params* that would allow copying `ty`
725724 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
726- let mut fulfill_cx = <dyn rustc_infer:: traits:: TraitEngine < ' _ > >:: new ( infcx. tcx ) ;
727-
728- let clone_did = infcx. tcx . lang_items ( ) . clone_trait ( ) . unwrap ( ) ;
729- let cause = ObligationCause :: new (
730- span,
731- self . mir_hir_id ( ) ,
732- rustc_infer:: traits:: ObligationCauseCode :: MiscObligation ,
733- ) ;
734- fulfill_cx. register_bound (
735- & infcx,
736- self . param_env ,
737- // Erase any region vids from the type, which may not be resolved
738- infcx. tcx . erase_regions ( ty) ,
739- clone_did,
740- cause,
741- ) ;
742- // Select all, including ambiguous predicates
743- let errors = fulfill_cx. select_all_or_error ( & infcx) ;
744- if errors. is_empty ( ) {
725+ let clone_did = tcx. lang_items ( ) . clone_trait ( ) . unwrap ( ) ;
726+ let params = ty:: List :: empty ( ) ;
727+ let ty = tcx. erase_regions ( ty) ;
728+ let env = self . param_env ;
729+ if infcx. type_implements_trait ( clone_did, ty, params, env) . must_apply_modulo_regions ( ) {
745730 err. span_suggestion_verbose (
746731 span. shrink_to_hi ( ) ,
747732 "consider cloning the value if the performance cost is acceptable" ,
0 commit comments