@@ -216,7 +216,22 @@ pub fn normalize<'a, 'b, 'tcx, T>(
216
216
where
217
217
T : TypeFoldable < ' tcx > ,
218
218
{
219
- normalize_with_depth ( selcx, param_env, cause, 0 , value)
219
+ let mut obligations = Vec :: new ( ) ;
220
+ let value = normalize_to ( selcx, param_env, cause, value, & mut obligations) ;
221
+ Normalized { value, obligations }
222
+ }
223
+
224
+ pub fn normalize_to < ' a , ' b , ' tcx , T > (
225
+ selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
226
+ param_env : ty:: ParamEnv < ' tcx > ,
227
+ cause : ObligationCause < ' tcx > ,
228
+ value : & T ,
229
+ obligations : & mut Vec < PredicateObligation < ' tcx > > ,
230
+ ) -> T
231
+ where
232
+ T : TypeFoldable < ' tcx > ,
233
+ {
234
+ normalize_with_depth_to ( selcx, param_env, cause, 0 , value, obligations)
220
235
}
221
236
222
237
/// As `normalize`, but with a custom depth.
@@ -227,11 +242,27 @@ pub fn normalize_with_depth<'a, 'b, 'tcx, T>(
227
242
depth : usize ,
228
243
value : & T ,
229
244
) -> Normalized < ' tcx , T >
245
+ where
246
+ T : TypeFoldable < ' tcx > ,
247
+ {
248
+ let mut obligations = Vec :: new ( ) ;
249
+ let value = normalize_with_depth_to ( selcx, param_env, cause, depth, value, & mut obligations) ;
250
+ Normalized { value, obligations }
251
+ }
252
+
253
+ pub fn normalize_with_depth_to < ' a , ' b , ' tcx , T > (
254
+ selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
255
+ param_env : ty:: ParamEnv < ' tcx > ,
256
+ cause : ObligationCause < ' tcx > ,
257
+ depth : usize ,
258
+ value : & T ,
259
+ obligations : & mut Vec < PredicateObligation < ' tcx > > ,
260
+ ) -> T
230
261
where
231
262
T : TypeFoldable < ' tcx > ,
232
263
{
233
264
debug ! ( "normalize_with_depth(depth={}, value={:?})" , depth, value) ;
234
- let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth) ;
265
+ let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth, obligations ) ;
235
266
let result = normalizer. fold ( value) ;
236
267
debug ! (
237
268
"normalize_with_depth: depth={} result={:?} with {} obligations" ,
@@ -240,14 +271,14 @@ where
240
271
normalizer. obligations. len( )
241
272
) ;
242
273
debug ! ( "normalize_with_depth: depth={} obligations={:?}" , depth, normalizer. obligations) ;
243
- Normalized { value : result, obligations : normalizer . obligations }
274
+ result
244
275
}
245
276
246
277
struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
247
278
selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
248
279
param_env : ty:: ParamEnv < ' tcx > ,
249
280
cause : ObligationCause < ' tcx > ,
250
- obligations : Vec < PredicateObligation < ' tcx > > ,
281
+ obligations : & ' a mut Vec < PredicateObligation < ' tcx > > ,
251
282
depth : usize ,
252
283
}
253
284
@@ -257,8 +288,9 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
257
288
param_env : ty:: ParamEnv < ' tcx > ,
258
289
cause : ObligationCause < ' tcx > ,
259
290
depth : usize ,
291
+ obligations : & ' a mut Vec < PredicateObligation < ' tcx > > ,
260
292
) -> AssocTypeNormalizer < ' a , ' b , ' tcx > {
261
- AssocTypeNormalizer { selcx, param_env, cause, obligations : vec ! [ ] , depth }
293
+ AssocTypeNormalizer { selcx, param_env, cause, obligations, depth }
262
294
}
263
295
264
296
fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : & T ) -> T {
@@ -343,7 +375,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
343
375
) ;
344
376
debug ! (
345
377
"AssocTypeNormalizer: depth={} normalized {:?} to {:?}, \
346
- now with {} obligations",
378
+ now with {} obligations",
347
379
self . depth,
348
380
ty,
349
381
normalized_ty,
@@ -441,8 +473,8 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
441
473
442
474
debug ! (
443
475
"opt_normalize_projection_type(\
444
- projection_ty={:?}, \
445
- depth={})",
476
+ projection_ty={:?}, \
477
+ depth={})",
446
478
projection_ty, depth
447
479
) ;
448
480
@@ -469,7 +501,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
469
501
// changes
470
502
debug ! (
471
503
"opt_normalize_projection_type: \
472
- found cache entry: ambiguous"
504
+ found cache entry: ambiguous"
473
505
) ;
474
506
if !projection_ty. has_closure_types ( ) {
475
507
return None ;
@@ -498,7 +530,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
498
530
499
531
debug ! (
500
532
"opt_normalize_projection_type: \
501
- found cache entry: in-progress"
533
+ found cache entry: in-progress"
502
534
) ;
503
535
504
536
// But for now, let's classify this as an overflow:
@@ -521,7 +553,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
521
553
// evaluations can causes ICEs (e.g., #43132).
522
554
debug ! (
523
555
"opt_normalize_projection_type: \
524
- found normalized ty `{:?}`",
556
+ found normalized ty `{:?}`",
525
557
ty
526
558
) ;
527
559
@@ -546,7 +578,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
546
578
Err ( ProjectionCacheEntry :: Error ) => {
547
579
debug ! (
548
580
"opt_normalize_projection_type: \
549
- found error"
581
+ found error"
550
582
) ;
551
583
let result = normalize_to_error ( selcx, param_env, projection_ty, cause, depth) ;
552
584
obligations. extend ( result. obligations ) ;
@@ -567,23 +599,28 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
567
599
568
600
debug ! (
569
601
"opt_normalize_projection_type: \
570
- projected_ty={:?} \
571
- depth={} \
572
- projected_obligations={:?}",
602
+ projected_ty={:?} \
603
+ depth={} \
604
+ projected_obligations={:?}",
573
605
projected_ty, depth, projected_obligations
574
606
) ;
575
607
576
608
let result = if projected_ty. has_projections ( ) {
577
- let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth + 1 ) ;
609
+ let mut normalizer = AssocTypeNormalizer :: new (
610
+ selcx,
611
+ param_env,
612
+ cause,
613
+ depth + 1 ,
614
+ & mut projected_obligations,
615
+ ) ;
578
616
let normalized_ty = normalizer. fold ( & projected_ty) ;
579
617
580
618
debug ! (
581
619
"opt_normalize_projection_type: \
582
- normalized_ty={:?} depth={}",
620
+ normalized_ty={:?} depth={}",
583
621
normalized_ty, depth
584
622
) ;
585
623
586
- projected_obligations. extend ( normalizer. obligations ) ;
587
624
Normalized { value : normalized_ty, obligations : projected_obligations }
588
625
} else {
589
626
Normalized { value : projected_ty, obligations : projected_obligations }
@@ -597,7 +634,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
597
634
Ok ( ProjectedTy :: NoProgress ( projected_ty) ) => {
598
635
debug ! (
599
636
"opt_normalize_projection_type: \
600
- projected_ty={:?} no progress",
637
+ projected_ty={:?} no progress",
601
638
projected_ty
602
639
) ;
603
640
let result = Normalized { value : projected_ty, obligations : vec ! [ ] } ;
@@ -608,7 +645,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
608
645
Err ( ProjectionTyError :: TooManyCandidates ) => {
609
646
debug ! (
610
647
"opt_normalize_projection_type: \
611
- too many candidates"
648
+ too many candidates"
612
649
) ;
613
650
infcx. projection_cache . borrow_mut ( ) . ambiguous ( cache_key) ;
614
651
None
@@ -930,7 +967,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx, I>(
930
967
931
968
debug ! (
932
969
"assemble_candidates_from_predicates: candidate={:?} \
933
- is_match={} same_def_id={}",
970
+ is_match={} same_def_id={}",
934
971
data, is_match, same_def_id
935
972
) ;
936
973
@@ -1192,7 +1229,7 @@ fn confirm_object_candidate<'cx, 'tcx>(
1192
1229
None => {
1193
1230
debug ! (
1194
1231
"confirm_object_candidate: no env-predicate \
1195
- found in object type `{:?}`; ill-formed",
1232
+ found in object type `{:?}`; ill-formed",
1196
1233
object_ty
1197
1234
) ;
1198
1235
return Progress :: error ( selcx. tcx ( ) ) ;
0 commit comments