@@ -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
}
@@ -452,26 +458,16 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
452
458
predicate,
453
459
) ) ;
454
460
}
455
- ty:: ConstKind :: Infer ( infer) => {
456
- let resolved = self . infcx . shallow_resolve ( infer) ;
457
- // the `InferConst` changed, meaning that we made progress.
458
- if resolved != infer {
459
- let cause = self . cause ( traits:: WellFormed ( None ) ) ;
460
-
461
- let resolved_constant = self . infcx . tcx . mk_const ( ty:: ConstS {
462
- kind : ty:: ConstKind :: Infer ( resolved) ,
463
- ty : constant. ty ( ) ,
464
- } ) ;
465
- self . out . push ( traits:: Obligation :: with_depth (
466
- cause,
467
- self . recursion_depth ,
468
- self . param_env ,
469
- ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed (
470
- resolved_constant. into ( ) ,
471
- ) )
461
+ ty:: ConstKind :: Infer ( _) => {
462
+ let cause = self . cause ( traits:: WellFormed ( None ) ) ;
463
+
464
+ self . out . push ( traits:: Obligation :: with_depth (
465
+ cause,
466
+ self . recursion_depth ,
467
+ self . param_env ,
468
+ ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( constant. into ( ) ) )
472
469
. to_predicate ( self . tcx ( ) ) ,
473
- ) ) ;
474
- }
470
+ ) ) ;
475
471
}
476
472
ty:: ConstKind :: Error ( _)
477
473
| ty:: ConstKind :: Param ( _)
@@ -627,7 +623,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
627
623
// of whatever returned this exact `impl Trait`.
628
624
629
625
// for named opaque `impl Trait` types we still need to check them
630
- if ty:: is_impl_trait_defn ( self . infcx . tcx , did) . is_none ( ) {
626
+ if ty:: is_impl_trait_defn ( self . tcx , did) . is_none ( ) {
631
627
let obligations = self . nominal_obligations ( did, substs) ;
632
628
self . out . extend ( obligations) ;
633
629
}
@@ -675,22 +671,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
675
671
// See also the comment on `fn obligations`, describing "livelock"
676
672
// prevention, which happens before this can be reached.
677
673
ty:: Infer ( _) => {
678
- let ty = self . infcx . shallow_resolve ( ty) ;
679
- if let ty:: Infer ( ty:: TyVar ( _) ) = ty. kind ( ) {
680
- // Not yet resolved, but we've made progress.
681
- let cause = self . cause ( traits:: WellFormed ( None ) ) ;
682
- self . out . push ( traits:: Obligation :: with_depth (
683
- cause,
684
- self . recursion_depth ,
685
- param_env,
686
- ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( ty. into ( ) ) )
687
- . to_predicate ( self . tcx ( ) ) ,
688
- ) ) ;
689
- } else {
690
- // Yes, resolved, proceed with the result.
691
- // FIXME(eddyb) add the type to `walker` instead of recursing.
692
- self . compute ( ty. into ( ) ) ;
693
- }
674
+ let cause = self . cause ( traits:: WellFormed ( None ) ) ;
675
+ self . out . push ( traits:: Obligation :: with_depth (
676
+ cause,
677
+ self . recursion_depth ,
678
+ param_env,
679
+ ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( ty. into ( ) ) )
680
+ . to_predicate ( self . tcx ( ) ) ,
681
+ ) ) ;
694
682
}
695
683
}
696
684
}
@@ -701,15 +689,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
701
689
def_id : DefId ,
702
690
substs : SubstsRef < ' tcx > ,
703
691
) -> Vec < traits:: PredicateObligation < ' tcx > > {
704
- let predicates = self . infcx . tcx . predicates_of ( def_id) ;
692
+ let predicates = self . tcx . predicates_of ( def_id) ;
705
693
let mut origins = vec ! [ def_id; predicates. predicates. len( ) ] ;
706
694
let mut head = predicates;
707
695
while let Some ( parent) = head. parent {
708
- head = self . infcx . tcx . predicates_of ( parent) ;
696
+ head = self . tcx . predicates_of ( parent) ;
709
697
origins. extend ( iter:: repeat ( parent) . take ( head. predicates . len ( ) ) ) ;
710
698
}
711
699
712
- let predicates = predicates. instantiate ( self . infcx . tcx , substs) ;
700
+ let predicates = predicates. instantiate ( self . tcx , substs) ;
713
701
debug_assert_eq ! ( predicates. predicates. len( ) , origins. len( ) ) ;
714
702
715
703
iter:: zip ( iter:: zip ( predicates. predicates , predicates. spans ) , origins. into_iter ( ) . rev ( ) )
@@ -764,7 +752,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
764
752
// Note: in fact we only permit builtin traits, not `Bar<'d>`, I
765
753
// am looking forward to the future here.
766
754
if !data. has_escaping_bound_vars ( ) && !region. has_escaping_bound_vars ( ) {
767
- let implicit_bounds = object_region_bounds ( self . infcx . tcx , data) ;
755
+ let implicit_bounds = object_region_bounds ( self . tcx , data) ;
768
756
769
757
let explicit_bound = region;
770
758
@@ -777,7 +765,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
777
765
cause,
778
766
self . recursion_depth ,
779
767
self . param_env ,
780
- outlives. to_predicate ( self . infcx . tcx ) ,
768
+ outlives. to_predicate ( self . tcx ) ,
781
769
) ) ;
782
770
}
783
771
}
0 commit comments