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