@@ -60,12 +60,19 @@ pub fn obligations<'a, 'tcx>(
60
60
GenericArgKind :: Lifetime ( ..) => return Some ( Vec :: new ( ) ) ,
61
61
} ;
62
62
63
- let mut wf =
64
- WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , recursion_depth, item : None } ;
63
+ let mut wf = WfPredicates {
64
+ tcx : infcx. tcx ,
65
+ param_env,
66
+ body_id,
67
+ span,
68
+ out : vec ! [ ] ,
69
+ recursion_depth,
70
+ item : None ,
71
+ } ;
65
72
wf. compute ( arg) ;
66
73
debug ! ( "wf::obligations({:?}, body_id={:?}) = {:?}" , arg, body_id, wf. out) ;
67
74
68
- let result = wf. normalize ( ) ;
75
+ let result = wf. normalize ( infcx ) ;
69
76
debug ! ( "wf::obligations({:?}, body_id={:?}) ~~> {:?}" , arg, body_id, result) ;
70
77
Some ( result)
71
78
}
@@ -83,7 +90,7 @@ pub fn trait_obligations<'a, 'tcx>(
83
90
item : & ' tcx hir:: Item < ' tcx > ,
84
91
) -> Vec < traits:: PredicateObligation < ' tcx > > {
85
92
let mut wf = WfPredicates {
86
- infcx,
93
+ tcx : infcx. tcx ,
87
94
param_env,
88
95
body_id,
89
96
span,
@@ -93,7 +100,7 @@ pub fn trait_obligations<'a, 'tcx>(
93
100
} ;
94
101
wf. compute_trait_ref ( trait_ref, Elaborate :: All ) ;
95
102
debug ! ( obligations = ?wf. out) ;
96
- wf. normalize ( )
103
+ wf. normalize ( infcx )
97
104
}
98
105
99
106
pub fn predicate_obligations < ' a , ' tcx > (
@@ -104,7 +111,7 @@ pub fn predicate_obligations<'a, 'tcx>(
104
111
span : Span ,
105
112
) -> Vec < traits:: PredicateObligation < ' tcx > > {
106
113
let mut wf = WfPredicates {
107
- infcx,
114
+ tcx : infcx. tcx ,
108
115
param_env,
109
116
body_id,
110
117
span,
@@ -159,11 +166,11 @@ pub fn predicate_obligations<'a, 'tcx>(
159
166
}
160
167
}
161
168
162
- wf. normalize ( )
169
+ wf. normalize ( infcx )
163
170
}
164
171
165
- struct WfPredicates < ' a , ' tcx > {
166
- infcx : & ' a InferCtxt < ' a , ' tcx > ,
172
+ struct WfPredicates < ' tcx > {
173
+ tcx : TyCtxt < ' tcx > ,
167
174
param_env : ty:: ParamEnv < ' tcx > ,
168
175
body_id : hir:: HirId ,
169
176
span : Span ,
@@ -260,18 +267,17 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
260
267
}
261
268
}
262
269
263
- impl < ' a , ' tcx > WfPredicates < ' a , ' tcx > {
270
+ impl < ' tcx > WfPredicates < ' tcx > {
264
271
fn tcx ( & self ) -> TyCtxt < ' tcx > {
265
- self . infcx . tcx
272
+ self . tcx
266
273
}
267
274
268
275
fn cause ( & self , code : traits:: ObligationCauseCode < ' tcx > ) -> traits:: ObligationCause < ' tcx > {
269
276
traits:: ObligationCause :: new ( self . span , self . body_id , code)
270
277
}
271
278
272
- fn normalize ( mut self ) -> Vec < traits:: PredicateObligation < ' tcx > > {
279
+ fn normalize ( self , infcx : & InferCtxt < ' _ , ' tcx > ) -> Vec < traits:: PredicateObligation < ' tcx > > {
273
280
let cause = self . cause ( traits:: WellFormed ( None ) ) ;
274
- let infcx = & mut self . infcx ;
275
281
let param_env = self . param_env ;
276
282
let mut obligations = Vec :: with_capacity ( self . out . len ( ) ) ;
277
283
for mut obligation in self . out {
@@ -296,7 +302,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
296
302
297
303
/// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
298
304
fn compute_trait_ref ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > , elaborate : Elaborate ) {
299
- let tcx = self . infcx . tcx ;
305
+ let tcx = self . tcx ;
300
306
let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref. substs ) ;
301
307
302
308
debug ! ( "compute_trait_ref obligations {:?}" , obligations) ;
@@ -410,14 +416,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
410
416
if !subty. has_escaping_bound_vars ( ) {
411
417
let cause = self . cause ( cause) ;
412
418
let trait_ref = ty:: TraitRef {
413
- def_id : self . infcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
414
- substs : self . infcx . tcx . mk_substs_trait ( subty, & [ ] ) ,
419
+ def_id : self . tcx . require_lang_item ( LangItem :: Sized , None ) ,
420
+ substs : self . tcx . mk_substs_trait ( subty, & [ ] ) ,
415
421
} ;
416
422
self . out . push ( traits:: Obligation :: with_depth (
417
423
cause,
418
424
self . recursion_depth ,
419
425
self . param_env ,
420
- ty:: Binder :: dummy ( trait_ref) . without_const ( ) . to_predicate ( self . infcx . tcx ) ,
426
+ ty:: Binder :: dummy ( trait_ref) . without_const ( ) . to_predicate ( self . tcx ) ,
421
427
) ) ;
422
428
}
423
429
}
@@ -617,7 +623,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
617
623
// of whatever returned this exact `impl Trait`.
618
624
619
625
// for named opaque `impl Trait` types we still need to check them
620
- if ty:: is_impl_trait_defn ( self . infcx . tcx , did) . is_none ( ) {
626
+ if ty:: is_impl_trait_defn ( self . tcx , did) . is_none ( ) {
621
627
let obligations = self . nominal_obligations ( did, substs) ;
622
628
self . out . extend ( obligations) ;
623
629
}
@@ -683,15 +689,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
683
689
def_id : DefId ,
684
690
substs : SubstsRef < ' tcx > ,
685
691
) -> Vec < traits:: PredicateObligation < ' tcx > > {
686
- let predicates = self . infcx . tcx . predicates_of ( def_id) ;
692
+ let predicates = self . tcx . predicates_of ( def_id) ;
687
693
let mut origins = vec ! [ def_id; predicates. predicates. len( ) ] ;
688
694
let mut head = predicates;
689
695
while let Some ( parent) = head. parent {
690
- head = self . infcx . tcx . predicates_of ( parent) ;
696
+ head = self . tcx . predicates_of ( parent) ;
691
697
origins. extend ( iter:: repeat ( parent) . take ( head. predicates . len ( ) ) ) ;
692
698
}
693
699
694
- let predicates = predicates. instantiate ( self . infcx . tcx , substs) ;
700
+ let predicates = predicates. instantiate ( self . tcx , substs) ;
695
701
debug_assert_eq ! ( predicates. predicates. len( ) , origins. len( ) ) ;
696
702
697
703
iter:: zip ( iter:: zip ( predicates. predicates , predicates. spans ) , origins. into_iter ( ) . rev ( ) )
@@ -746,7 +752,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
746
752
// Note: in fact we only permit builtin traits, not `Bar<'d>`, I
747
753
// am looking forward to the future here.
748
754
if !data. has_escaping_bound_vars ( ) && !region. has_escaping_bound_vars ( ) {
749
- let implicit_bounds = object_region_bounds ( self . infcx . tcx , data) ;
755
+ let implicit_bounds = object_region_bounds ( self . tcx , data) ;
750
756
751
757
let explicit_bound = region;
752
758
@@ -759,7 +765,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
759
765
cause,
760
766
self . recursion_depth ,
761
767
self . param_env ,
762
- outlives. to_predicate ( self . infcx . tcx ) ,
768
+ outlives. to_predicate ( self . tcx ) ,
763
769
) ) ;
764
770
}
765
771
}
0 commit comments