@@ -42,13 +42,11 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
4242use  rustc_infer:: infer:: UpvarRegion ; 
4343use  rustc_middle:: hir:: place:: { Place ,  PlaceBase ,  PlaceWithHirId ,  Projection ,  ProjectionKind } ; 
4444use  rustc_middle:: mir:: FakeReadCause ; 
45- use  rustc_middle:: ty:: { 
46-     self ,  ClosureSizeProfileData ,  TraitRef ,  Ty ,  TyCtxt ,  TypeckResults ,  UpvarSubsts , 
47- } ; 
45+ use  rustc_middle:: ty:: { self ,  ClosureSizeProfileData ,  Ty ,  TyCtxt ,  TypeckResults ,  UpvarSubsts } ; 
4846use  rustc_session:: lint; 
4947use  rustc_span:: sym; 
5048use  rustc_span:: { MultiSpan ,  Span ,  Symbol } ; 
51- use  rustc_trait_selection:: traits :: { Obligation ,   ObligationCause } ; 
49+ use  rustc_trait_selection:: infer :: InferCtxtExt ; 
5250
5351use  rustc_data_structures:: stable_set:: FxHashSet ; 
5452use  rustc_index:: vec:: Idx ; 
@@ -578,29 +576,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578576        reasons
579577    } 
580578
581-     /// Returns true if `ty` may implement `trait_def_id` 
582-      fn  ty_impls_trait ( 
583-         & self , 
584-         ty :  Ty < ' tcx > , 
585-         cause :  & ObligationCause < ' tcx > , 
586-         trait_def_id :  DefId , 
587-     )  -> bool  { 
588-         use  crate :: rustc_middle:: ty:: ToPredicate ; 
589-         use  crate :: rustc_middle:: ty:: WithConstness ; 
590-         use  rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ; 
591-         let  tcx = self . infcx . tcx ; 
592- 
593-         let  trait_ref = TraitRef  {  def_id :  trait_def_id,  substs :  tcx. mk_substs_trait ( ty,  & [ ] )  } ; 
594- 
595-         let  obligation = Obligation :: new ( 
596-             cause. clone ( ) , 
597-             self . param_env , 
598-             trait_ref. without_const ( ) . to_predicate ( tcx) , 
599-         ) ; 
600- 
601-         self . infcx . predicate_may_hold ( & obligation) 
602-     } 
603- 
604579    /// Returns true if migration is needed for trait for the provided var_hir_id 
605580     fn  need_2229_migrations_for_trait ( 
606581        & self , 
@@ -618,10 +593,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
618593
619594        let  ty = self . infcx . resolve_vars_if_possible ( self . node_ty ( var_hir_id) ) ; 
620595
621-         let  cause = ObligationCause :: misc ( self . tcx . hir ( ) . span ( var_hir_id) ,  self . body_id ) ; 
622- 
623596        let  obligation_should_hold = check_trait
624-             . map ( |check_trait| self . ty_impls_trait ( ty,  & cause,  check_trait) ) 
597+             . map ( |check_trait| { 
598+                 self . infcx 
599+                     . type_implements_trait ( 
600+                         check_trait, 
601+                         ty, 
602+                         self . tcx . mk_substs_trait ( ty,  & [ ] ) , 
603+                         self . param_env , 
604+                     ) 
605+                     . must_apply_modulo_regions ( ) 
606+             } ) 
625607            . unwrap_or ( false ) ; 
626608
627609        // Check whether catpured fields also implement the trait 
@@ -630,7 +612,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630612            let  ty = capture. place . ty ( ) ; 
631613
632614            let  obligation_holds_for_capture = check_trait
633-                 . map ( |check_trait| self . ty_impls_trait ( ty,  & cause,  check_trait) ) 
615+                 . map ( |check_trait| { 
616+                     self . infcx 
617+                         . type_implements_trait ( 
618+                             check_trait, 
619+                             ty, 
620+                             self . tcx . mk_substs_trait ( ty,  & [ ] ) , 
621+                             self . param_env , 
622+                         ) 
623+                         . must_apply_modulo_regions ( ) 
624+                 } ) 
634625                . unwrap_or ( false ) ; 
635626
636627            if  !obligation_holds_for_capture && obligation_should_hold { 
@@ -961,13 +952,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
961952        let  is_drop_defined_for_ty = |ty :  Ty < ' tcx > | { 
962953            let  drop_trait = self . tcx . require_lang_item ( hir:: LangItem :: Drop ,  Some ( closure_span) ) ; 
963954            let  ty_params = self . tcx . mk_substs_trait ( base_path_ty,  & [ ] ) ; 
964-             self . tcx 
965-                 . type_implements_trait ( ( 
955+             self . infcx 
956+                 . type_implements_trait ( 
966957                    drop_trait, 
967958                    ty, 
968959                    ty_params, 
969960                    self . tcx . param_env ( closure_def_id. expect_local ( ) ) , 
970-                 ) ) 
961+                 ) 
971962                . must_apply_modulo_regions ( ) 
972963        } ; 
973964
0 commit comments