@@ -42,13 +42,11 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
42
42
use rustc_infer:: infer:: UpvarRegion ;
43
43
use rustc_middle:: hir:: place:: { Place , PlaceBase , PlaceWithHirId , Projection , ProjectionKind } ;
44
44
use 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 } ;
48
46
use rustc_session:: lint;
49
47
use rustc_span:: sym;
50
48
use rustc_span:: { MultiSpan , Span , Symbol } ;
51
- use rustc_trait_selection:: traits :: { Obligation , ObligationCause } ;
49
+ use rustc_trait_selection:: infer :: InferCtxtExt ;
52
50
53
51
use rustc_data_structures:: stable_set:: FxHashSet ;
54
52
use rustc_index:: vec:: Idx ;
@@ -578,29 +576,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578
576
reasons
579
577
}
580
578
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
-
604
579
/// Returns true if migration is needed for trait for the provided var_hir_id
605
580
fn need_2229_migrations_for_trait (
606
581
& self ,
@@ -618,10 +593,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
618
593
619
594
let ty = self . infcx . resolve_vars_if_possible ( self . node_ty ( var_hir_id) ) ;
620
595
621
- let cause = ObligationCause :: misc ( self . tcx . hir ( ) . span ( var_hir_id) , self . body_id ) ;
622
-
623
596
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
+ } )
625
607
. unwrap_or ( false ) ;
626
608
627
609
// Check whether catpured fields also implement the trait
@@ -630,7 +612,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630
612
let ty = capture. place . ty ( ) ;
631
613
632
614
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
+ } )
634
625
. unwrap_or ( false ) ;
635
626
636
627
if !obligation_holds_for_capture && obligation_should_hold {
@@ -961,13 +952,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
961
952
let is_drop_defined_for_ty = |ty : Ty < ' tcx > | {
962
953
let drop_trait = self . tcx . require_lang_item ( hir:: LangItem :: Drop , Some ( closure_span) ) ;
963
954
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 (
966
957
drop_trait,
967
958
ty,
968
959
ty_params,
969
960
self . tcx . param_env ( closure_def_id. expect_local ( ) ) ,
970
- ) )
961
+ )
971
962
. must_apply_modulo_regions ( )
972
963
} ;
973
964
0 commit comments