@@ -315,9 +315,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
315
315
fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : T ) -> T {
316
316
let value = self . selcx . infcx ( ) . resolve_vars_if_possible ( value) ;
317
317
318
- if value. has_escaping_bound_vars ( ) {
319
- bug ! ( "Normalizing without wrapping in a `Binder`" ) ;
320
- }
318
+ assert ! (
319
+ !value. has_escaping_bound_vars( ) ,
320
+ "Normalizing {:?} without wrapping in a `Binder`" ,
321
+ value
322
+ ) ;
321
323
322
324
if !value. has_projections ( ) { value } else { value. fold_with ( self ) }
323
325
}
@@ -427,40 +429,36 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
427
429
// give up and fall back to pretending like we never tried!
428
430
429
431
let infcx = self . selcx . infcx ( ) ;
430
- let replaced =
432
+ let ( data , mapped_regions , mapped_types , mapped_consts ) =
431
433
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , data) ;
432
- if let Some ( ( data, mapped_regions, mapped_types, mapped_consts) ) = replaced {
433
- let normalized_ty = opt_normalize_projection_type (
434
- self . selcx ,
435
- self . param_env ,
436
- data,
437
- self . cause . clone ( ) ,
438
- self . depth ,
439
- & mut self . obligations ,
440
- )
441
- . ok ( )
442
- . flatten ( )
443
- . unwrap_or_else ( || ty) ;
444
-
445
- let normalized_ty = PlaceholderReplacer :: replace_placeholders (
446
- infcx,
447
- mapped_regions,
448
- mapped_types,
449
- mapped_consts,
450
- & self . universes ,
451
- normalized_ty,
452
- ) ;
453
- debug ! (
454
- ?self . depth,
455
- ?ty,
456
- ?normalized_ty,
457
- obligations. len = ?self . obligations. len( ) ,
458
- "AssocTypeNormalizer: normalized type"
459
- ) ;
460
- normalized_ty
461
- } else {
462
- ty
463
- }
434
+ let normalized_ty = opt_normalize_projection_type (
435
+ self . selcx ,
436
+ self . param_env ,
437
+ data,
438
+ self . cause . clone ( ) ,
439
+ self . depth ,
440
+ & mut self . obligations ,
441
+ )
442
+ . ok ( )
443
+ . flatten ( )
444
+ . unwrap_or_else ( || ty) ;
445
+
446
+ let normalized_ty = PlaceholderReplacer :: replace_placeholders (
447
+ infcx,
448
+ mapped_regions,
449
+ mapped_types,
450
+ mapped_consts,
451
+ & self . universes ,
452
+ normalized_ty,
453
+ ) ;
454
+ debug ! (
455
+ ?self . depth,
456
+ ?ty,
457
+ ?normalized_ty,
458
+ obligations. len = ?self . obligations. len( ) ,
459
+ "AssocTypeNormalizer: normalized type"
460
+ ) ;
461
+ normalized_ty
464
462
}
465
463
466
464
_ => ty,
@@ -491,14 +489,6 @@ pub struct BoundVarReplacer<'me, 'tcx> {
491
489
// The `UniverseIndex` of the binding levels above us. These are optional, since we are lazy:
492
490
// we don't actually create a universe until we see a bound var we have to replace.
493
491
universe_indices : & ' me mut Vec < Option < ty:: UniverseIndex > > ,
494
- // FIXME: So, this is a less-than-ideal solution to a problem we want to solve eventually. Ideally, we
495
- // shouldn't need to worry about bound vars for which we haven't passed (`self.current_index`)
496
- // or that we don't explicitly know about (`self.universe_indices`). This is true for
497
- // `AssocTypeNormalizer` but not `QueryNormalizer` currently. When we can always know about
498
- // any binding levels above us, we can remove this. (The alternative would be
499
- // `outer_exclusive_binder`, but that only exists on `Ty`. Otherwise, we would have to visit
500
- // through the `T`, which we specifically want to avoid not being lazy.)
501
- failed : bool ,
502
492
}
503
493
504
494
impl < ' me , ' tcx > BoundVarReplacer < ' me , ' tcx > {
@@ -508,12 +498,12 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
508
498
infcx : & ' me InferCtxt < ' me , ' tcx > ,
509
499
universe_indices : & ' me mut Vec < Option < ty:: UniverseIndex > > ,
510
500
value : T ,
511
- ) -> Option < (
501
+ ) -> (
512
502
T ,
513
503
BTreeMap < ty:: PlaceholderRegion , ty:: BoundRegion > ,
514
504
BTreeMap < ty:: PlaceholderType , ty:: BoundTy > ,
515
505
BTreeMap < ty:: PlaceholderConst < ' tcx > , ty:: BoundVar > ,
516
- ) > {
506
+ ) {
517
507
let mapped_regions: BTreeMap < ty:: PlaceholderRegion , ty:: BoundRegion > = BTreeMap :: new ( ) ;
518
508
let mapped_types: BTreeMap < ty:: PlaceholderType , ty:: BoundTy > = BTreeMap :: new ( ) ;
519
509
let mapped_consts: BTreeMap < ty:: PlaceholderConst < ' tcx > , ty:: BoundVar > = BTreeMap :: new ( ) ;
@@ -525,14 +515,24 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> {
525
515
mapped_consts,
526
516
current_index : ty:: INNERMOST ,
527
517
universe_indices,
528
- failed : false ,
529
518
} ;
530
519
531
520
let value = value. super_fold_with ( & mut replacer) ;
532
521
533
- ( !replacer. failed ) . then ( || {
534
- ( value, replacer. mapped_regions , replacer. mapped_types , replacer. mapped_consts )
535
- } )
522
+ ( value, replacer. mapped_regions , replacer. mapped_types , replacer. mapped_consts )
523
+ }
524
+
525
+ fn universe_for ( & mut self , debruijn : ty:: DebruijnIndex ) -> ty:: UniverseIndex {
526
+ let infcx = self . infcx ;
527
+ let index =
528
+ self . universe_indices . len ( ) - debruijn. as_usize ( ) + self . current_index . as_usize ( ) - 1 ;
529
+ let universe = self . universe_indices [ index] . unwrap_or_else ( || {
530
+ for i in self . universe_indices . iter_mut ( ) . take ( index + 1 ) {
531
+ * i = i. or_else ( || Some ( infcx. create_next_universe ( ) ) )
532
+ }
533
+ self . universe_indices [ index] . unwrap ( )
534
+ } ) ;
535
+ universe
536
536
}
537
537
}
538
538
@@ -557,20 +557,10 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
557
557
if debruijn. as_usize ( ) + 1
558
558
> self . current_index . as_usize ( ) + self . universe_indices . len ( ) =>
559
559
{
560
- self . failed = true ;
561
- r
560
+ bug ! ( "Bound vars outside of `self.universe_indices`" ) ;
562
561
}
563
562
ty:: ReLateBound ( debruijn, br) if debruijn >= self . current_index => {
564
- let infcx = self . infcx ;
565
- let index = self . universe_indices . len ( ) - debruijn. as_usize ( )
566
- + self . current_index . as_usize ( )
567
- - 1 ;
568
- let universe = self . universe_indices [ index] . unwrap_or_else ( || {
569
- for i in self . universe_indices . iter_mut ( ) . take ( index + 1 ) {
570
- * i = i. or_else ( || Some ( infcx. create_next_universe ( ) ) )
571
- }
572
- self . universe_indices [ index] . unwrap ( )
573
- } ) ;
563
+ let universe = self . universe_for ( debruijn) ;
574
564
let p = ty:: PlaceholderRegion { universe, name : br. kind } ;
575
565
self . mapped_regions . insert ( p. clone ( ) , br) ;
576
566
self . infcx . tcx . mk_region ( ty:: RePlaceholder ( p) )
@@ -585,20 +575,10 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
585
575
if debruijn. as_usize ( ) + 1
586
576
> self . current_index . as_usize ( ) + self . universe_indices . len ( ) =>
587
577
{
588
- self . failed = true ;
589
- t
578
+ bug ! ( "Bound vars outside of `self.universe_indices`" ) ;
590
579
}
591
580
ty:: Bound ( debruijn, bound_ty) if debruijn >= self . current_index => {
592
- let infcx = self . infcx ;
593
- let index = self . universe_indices . len ( ) - debruijn. as_usize ( )
594
- + self . current_index . as_usize ( )
595
- - 1 ;
596
- let universe = self . universe_indices [ index] . unwrap_or_else ( || {
597
- for i in self . universe_indices . iter_mut ( ) . take ( index + 1 ) {
598
- * i = i. or_else ( || Some ( infcx. create_next_universe ( ) ) )
599
- }
600
- self . universe_indices [ index] . unwrap ( )
601
- } ) ;
581
+ let universe = self . universe_for ( debruijn) ;
602
582
let p = ty:: PlaceholderType { universe, name : bound_ty. var } ;
603
583
self . mapped_types . insert ( p. clone ( ) , bound_ty) ;
604
584
self . infcx . tcx . mk_ty ( ty:: Placeholder ( p) )
@@ -614,22 +594,12 @@ impl TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
614
594
if debruijn. as_usize ( ) + 1
615
595
> self . current_index . as_usize ( ) + self . universe_indices . len ( ) =>
616
596
{
617
- self . failed = true ;
618
- ct
597
+ bug ! ( "Bound vars outside of `self.universe_indices`" ) ;
619
598
}
620
599
ty:: Const { val : ty:: ConstKind :: Bound ( debruijn, bound_const) , ty }
621
600
if debruijn >= self . current_index =>
622
601
{
623
- let infcx = self . infcx ;
624
- let index = self . universe_indices . len ( ) - debruijn. as_usize ( )
625
- + self . current_index . as_usize ( )
626
- - 1 ;
627
- let universe = self . universe_indices [ index] . unwrap_or_else ( || {
628
- for i in self . universe_indices . iter_mut ( ) . take ( index + 1 ) {
629
- * i = i. or_else ( || Some ( infcx. create_next_universe ( ) ) )
630
- }
631
- self . universe_indices [ index] . unwrap ( )
632
- } ) ;
602
+ let universe = self . universe_for ( debruijn) ;
633
603
let p = ty:: PlaceholderConst {
634
604
universe,
635
605
name : ty:: BoundConst { var : bound_const, ty } ,
0 commit comments