@@ -20,6 +20,7 @@ pub fn obligations<'a, 'tcx>(
20
20
infcx : & InferCtxt < ' a , ' tcx > ,
21
21
param_env : ty:: ParamEnv < ' tcx > ,
22
22
body_id : hir:: HirId ,
23
+ recursion_depth : usize ,
23
24
arg : GenericArg < ' tcx > ,
24
25
span : Span ,
25
26
) -> Option < Vec < traits:: PredicateObligation < ' tcx > > > {
@@ -59,7 +60,8 @@ pub fn obligations<'a, 'tcx>(
59
60
GenericArgKind :: Lifetime ( ..) => return Some ( Vec :: new ( ) ) ,
60
61
} ;
61
62
62
- let mut wf = WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , item : None } ;
63
+ let mut wf =
64
+ WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , recursion_depth, item : None } ;
63
65
wf. compute ( arg) ;
64
66
debug ! ( "wf::obligations({:?}, body_id={:?}) = {:?}" , arg, body_id, wf. out) ;
65
67
@@ -80,7 +82,8 @@ pub fn trait_obligations<'a, 'tcx>(
80
82
span : Span ,
81
83
item : Option < & ' tcx hir:: Item < ' tcx > > ,
82
84
) -> Vec < traits:: PredicateObligation < ' tcx > > {
83
- let mut wf = WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , item } ;
85
+ let mut wf =
86
+ WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , recursion_depth : 0 , item } ;
84
87
wf. compute_trait_ref ( trait_ref, Elaborate :: All ) ;
85
88
wf. normalize ( )
86
89
}
@@ -92,7 +95,15 @@ pub fn predicate_obligations<'a, 'tcx>(
92
95
predicate : ty:: Predicate < ' tcx > ,
93
96
span : Span ,
94
97
) -> Vec < traits:: PredicateObligation < ' tcx > > {
95
- let mut wf = WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , item : None } ;
98
+ let mut wf = WfPredicates {
99
+ infcx,
100
+ param_env,
101
+ body_id,
102
+ span,
103
+ out : vec ! [ ] ,
104
+ recursion_depth : 0 ,
105
+ item : None ,
106
+ } ;
96
107
97
108
// It's ok to skip the binder here because wf code is prepared for it
98
109
match predicate. skip_binders ( ) {
@@ -142,6 +153,7 @@ struct WfPredicates<'a, 'tcx> {
142
153
body_id : hir:: HirId ,
143
154
span : Span ,
144
155
out : Vec < traits:: PredicateObligation < ' tcx > > ,
156
+ recursion_depth : usize ,
145
157
item : Option < & ' tcx hir:: Item < ' tcx > > ,
146
158
}
147
159
@@ -249,19 +261,19 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
249
261
for mut obligation in self . out {
250
262
assert ! ( !obligation. has_escaping_bound_vars( ) ) ;
251
263
let mut selcx = traits:: SelectionContext :: new ( infcx) ;
252
- let i = obligations. len ( ) ;
253
264
// Don't normalize the whole obligation, the param env is either
254
265
// already normalized, or we're currently normalizing the
255
266
// param_env. Either way we should only normalize the predicate.
256
- let normalized_predicate = traits:: normalize_to (
267
+ let normalized_predicate = traits:: project :: normalize_with_depth_to (
257
268
& mut selcx,
258
269
param_env,
259
270
cause. clone ( ) ,
271
+ self . recursion_depth ,
260
272
& obligation. predicate ,
261
273
& mut obligations,
262
274
) ;
263
275
obligation. predicate = normalized_predicate;
264
- obligations. insert ( i , obligation) ;
276
+ obligations. push ( obligation) ;
265
277
}
266
278
obligations
267
279
}
@@ -274,6 +286,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
274
286
debug ! ( "compute_trait_ref obligations {:?}" , obligations) ;
275
287
let cause = self . cause ( traits:: MiscObligation ) ;
276
288
let param_env = self . param_env ;
289
+ let depth = self . recursion_depth ;
277
290
278
291
let item = self . item ;
279
292
@@ -295,7 +308,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
295
308
& obligation. predicate ,
296
309
tcx. associated_items ( trait_ref. def_id ) . in_definition_order ( ) ,
297
310
) ;
298
- traits:: Obligation :: new ( cause, param_env, obligation. predicate )
311
+ traits:: Obligation :: with_depth ( cause, depth , param_env, obligation. predicate )
299
312
} ;
300
313
301
314
if let Elaborate :: All = elaborate {
@@ -324,8 +337,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
324
337
new_cause. make_mut ( ) . span = self_ty. span ;
325
338
}
326
339
}
327
- traits:: Obligation :: new (
340
+ traits:: Obligation :: with_depth (
328
341
new_cause,
342
+ depth,
329
343
param_env,
330
344
ty:: PredicateAtom :: WellFormed ( arg) . to_predicate ( tcx) ,
331
345
)
@@ -363,6 +377,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
363
377
let tcx = self . tcx ( ) ;
364
378
let cause = self . cause ( traits:: MiscObligation ) ;
365
379
let param_env = self . param_env ;
380
+ let depth = self . recursion_depth ;
366
381
367
382
self . out . extend (
368
383
data. substs
@@ -372,8 +387,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
372
387
} )
373
388
. filter ( |arg| !arg. has_escaping_bound_vars ( ) )
374
389
. map ( |arg| {
375
- traits:: Obligation :: new (
390
+ traits:: Obligation :: with_depth (
376
391
cause. clone ( ) ,
392
+ depth,
377
393
param_env,
378
394
ty:: PredicateKind :: WellFormed ( arg) . to_predicate ( tcx) ,
379
395
)
@@ -388,8 +404,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
388
404
def_id : self . infcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
389
405
substs : self . infcx . tcx . mk_substs_trait ( subty, & [ ] ) ,
390
406
} ;
391
- self . out . push ( traits:: Obligation :: new (
407
+ self . out . push ( traits:: Obligation :: with_depth (
392
408
cause,
409
+ self . recursion_depth ,
393
410
self . param_env ,
394
411
trait_ref. without_const ( ) . to_predicate ( self . infcx . tcx ) ,
395
412
) ) ;
@@ -400,6 +417,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
400
417
fn compute ( & mut self , arg : GenericArg < ' tcx > ) {
401
418
let mut walker = arg. walk ( ) ;
402
419
let param_env = self . param_env ;
420
+ let depth = self . recursion_depth ;
403
421
while let Some ( arg) = walker. next ( ) {
404
422
let ty = match arg. unpack ( ) {
405
423
GenericArgKind :: Type ( ty) => ty,
@@ -419,8 +437,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
419
437
let predicate = ty:: PredicateAtom :: ConstEvaluatable ( def, substs)
420
438
. to_predicate ( self . tcx ( ) ) ;
421
439
let cause = self . cause ( traits:: MiscObligation ) ;
422
- self . out . push ( traits:: Obligation :: new (
440
+ self . out . push ( traits:: Obligation :: with_depth (
423
441
cause,
442
+ self . recursion_depth ,
424
443
self . param_env ,
425
444
predicate,
426
445
) ) ;
@@ -435,8 +454,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
435
454
val : ty:: ConstKind :: Infer ( resolved) ,
436
455
..* constant
437
456
} ) ;
438
- self . out . push ( traits:: Obligation :: new (
457
+ self . out . push ( traits:: Obligation :: with_depth (
439
458
cause,
459
+ self . recursion_depth ,
440
460
self . param_env ,
441
461
ty:: PredicateAtom :: WellFormed ( resolved_constant. into ( ) )
442
462
. to_predicate ( self . tcx ( ) ) ,
@@ -521,8 +541,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
521
541
// WfReference
522
542
if !r. has_escaping_bound_vars ( ) && !rty. has_escaping_bound_vars ( ) {
523
543
let cause = self . cause ( traits:: ReferenceOutlivesReferent ( ty) ) ;
524
- self . out . push ( traits:: Obligation :: new (
544
+ self . out . push ( traits:: Obligation :: with_depth (
525
545
cause,
546
+ depth,
526
547
param_env,
527
548
ty:: PredicateAtom :: TypeOutlives ( ty:: OutlivesPredicate ( rty, r) )
528
549
. to_predicate ( self . tcx ( ) ) ,
@@ -612,8 +633,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
612
633
let component_traits = data. auto_traits ( ) . chain ( data. principal_def_id ( ) ) ;
613
634
let tcx = self . tcx ( ) ;
614
635
self . out . extend ( component_traits. map ( |did| {
615
- traits:: Obligation :: new (
636
+ traits:: Obligation :: with_depth (
616
637
cause. clone ( ) ,
638
+ depth,
617
639
param_env,
618
640
ty:: PredicateAtom :: ObjectSafe ( did) . to_predicate ( tcx) ,
619
641
)
@@ -638,8 +660,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
638
660
if let ty:: Infer ( ty:: TyVar ( _) ) = ty. kind ( ) {
639
661
// Not yet resolved, but we've made progress.
640
662
let cause = self . cause ( traits:: MiscObligation ) ;
641
- self . out . push ( traits:: Obligation :: new (
663
+ self . out . push ( traits:: Obligation :: with_depth (
642
664
cause,
665
+ self . recursion_depth ,
643
666
param_env,
644
667
ty:: PredicateAtom :: WellFormed ( ty. into ( ) ) . to_predicate ( self . tcx ( ) ) ,
645
668
) ) ;
@@ -676,7 +699,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
676
699
. zip ( origins. into_iter ( ) . rev ( ) )
677
700
. map ( |( ( pred, span) , origin_def_id) | {
678
701
let cause = self . cause ( traits:: BindingObligation ( origin_def_id, span) ) ;
679
- traits:: Obligation :: new ( cause, self . param_env , pred)
702
+ traits:: Obligation :: with_depth ( cause, self . recursion_depth , self . param_env , pred)
680
703
} )
681
704
. filter ( |pred| !pred. has_escaping_bound_vars ( ) )
682
705
. collect ( )
@@ -729,8 +752,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
729
752
let cause = self . cause ( traits:: ObjectTypeBound ( ty, explicit_bound) ) ;
730
753
let outlives =
731
754
ty:: Binder :: dummy ( ty:: OutlivesPredicate ( explicit_bound, implicit_bound) ) ;
732
- self . out . push ( traits:: Obligation :: new (
755
+ self . out . push ( traits:: Obligation :: with_depth (
733
756
cause,
757
+ self . recursion_depth ,
734
758
self . param_env ,
735
759
outlives. to_predicate ( self . infcx . tcx ) ,
736
760
) ) ;
0 commit comments