@@ -173,8 +173,10 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
173
173
match r. kind ( ) {
174
174
ty:: ReLateParam ( _) | ty:: ReErased | ty:: ReStatic | ty:: ReEarlyParam ( ..) => r,
175
175
176
- ty:: RePlaceholder ( placeholder) => canonicalizer
177
- . canonical_var_for_region ( CanonicalVarKind :: PlaceholderRegion ( placeholder) , r) ,
176
+ ty:: RePlaceholder ( placeholder) => canonicalizer. canonical_var_for_region (
177
+ CanonicalVarKind :: PlaceholderRegion ( placeholder. universe ) ,
178
+ r,
179
+ ) ,
178
180
179
181
ty:: ReVar ( vid) => {
180
182
let universe = infcx
@@ -288,7 +290,7 @@ struct Canonicalizer<'cx, 'tcx> {
288
290
/// Set to `None` to disable the resolution of inference variables.
289
291
infcx : Option < & ' cx InferCtxt < ' tcx > > ,
290
292
tcx : TyCtxt < ' tcx > ,
291
- variables : SmallVec < [ CanonicalVarKind < ' tcx > ; 8 ] > ,
293
+ variables : SmallVec < [ CanonicalVarKind ; 8 ] > ,
292
294
query_state : & ' cx mut OriginalQueryValues < ' tcx > ,
293
295
// Note that indices is only used once `var_values` is big enough to be
294
296
// heap-allocated.
@@ -390,11 +392,13 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
390
392
bug ! ( "encountered a fresh type during canonicalization" )
391
393
}
392
394
393
- ty:: Placeholder ( mut placeholder) => {
394
- if !self . canonicalize_mode . preserve_universes ( ) {
395
- placeholder. universe = ty:: UniverseIndex :: ROOT ;
396
- }
397
- self . canonicalize_ty_var ( CanonicalVarKind :: PlaceholderTy ( placeholder) , t)
395
+ ty:: Placeholder ( placeholder) => {
396
+ let universe = if self . canonicalize_mode . preserve_universes ( ) {
397
+ placeholder. universe
398
+ } else {
399
+ ty:: UniverseIndex :: ROOT
400
+ } ;
401
+ self . canonicalize_ty_var ( CanonicalVarKind :: PlaceholderTy ( universe) , t)
398
402
}
399
403
400
404
ty:: Bound ( debruijn, _) => {
@@ -481,8 +485,13 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
481
485
}
482
486
}
483
487
ty:: ConstKind :: Placeholder ( placeholder) => {
488
+ let universe = if self . canonicalize_mode . preserve_universes ( ) {
489
+ placeholder. universe
490
+ } else {
491
+ ty:: UniverseIndex :: ROOT
492
+ } ;
484
493
return self
485
- . canonicalize_const_var ( CanonicalVarKind :: PlaceholderConst ( placeholder ) , ct) ;
494
+ . canonicalize_const_var ( CanonicalVarKind :: PlaceholderConst ( universe ) , ct) ;
486
495
}
487
496
_ => { }
488
497
}
@@ -588,11 +597,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
588
597
/// or returns an existing variable if `kind` has already been
589
598
/// seen. `kind` is expected to be an unbound variable (or
590
599
/// potentially a free region).
591
- fn canonical_var (
592
- & mut self ,
593
- var_kind : CanonicalVarKind < ' tcx > ,
594
- value : GenericArg < ' tcx > ,
595
- ) -> BoundVar {
600
+ fn canonical_var ( & mut self , var_kind : CanonicalVarKind , value : GenericArg < ' tcx > ) -> BoundVar {
596
601
let Canonicalizer { variables, query_state, indices, .. } = self ;
597
602
598
603
let var_values = & mut query_state. var_values ;
@@ -655,7 +660,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
655
660
/// Replaces the universe indexes used in `var_values` with their index in
656
661
/// `query_state.universe_map`. This minimizes the maximum universe used in
657
662
/// the canonicalized value.
658
- fn universe_canonicalized_variables ( self ) -> SmallVec < [ CanonicalVarKind < ' tcx > ; 8 ] > {
663
+ fn universe_canonicalized_variables ( self ) -> SmallVec < [ CanonicalVarKind ; 8 ] > {
659
664
if self . query_state . universe_map . len ( ) == 1 {
660
665
return self . variables ;
661
666
}
@@ -679,23 +684,14 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
679
684
}
680
685
CanonicalVarKind :: Region ( u) => CanonicalVarKind :: Region ( reverse_universe_map[ & u] ) ,
681
686
CanonicalVarKind :: Const ( u) => CanonicalVarKind :: Const ( reverse_universe_map[ & u] ) ,
682
- CanonicalVarKind :: PlaceholderTy ( placeholder) => {
683
- CanonicalVarKind :: PlaceholderTy ( ty:: Placeholder {
684
- universe : reverse_universe_map[ & placeholder. universe ] ,
685
- ..placeholder
686
- } )
687
+ CanonicalVarKind :: PlaceholderTy ( ui) => {
688
+ CanonicalVarKind :: PlaceholderTy ( reverse_universe_map[ & ui] )
687
689
}
688
- CanonicalVarKind :: PlaceholderRegion ( placeholder) => {
689
- CanonicalVarKind :: PlaceholderRegion ( ty:: Placeholder {
690
- universe : reverse_universe_map[ & placeholder. universe ] ,
691
- ..placeholder
692
- } )
690
+ CanonicalVarKind :: PlaceholderRegion ( ui) => {
691
+ CanonicalVarKind :: PlaceholderRegion ( reverse_universe_map[ & ui] )
693
692
}
694
- CanonicalVarKind :: PlaceholderConst ( placeholder) => {
695
- CanonicalVarKind :: PlaceholderConst ( ty:: Placeholder {
696
- universe : reverse_universe_map[ & placeholder. universe ] ,
697
- ..placeholder
698
- } )
693
+ CanonicalVarKind :: PlaceholderConst ( ui) => {
694
+ CanonicalVarKind :: PlaceholderConst ( reverse_universe_map[ & ui] )
699
695
}
700
696
} )
701
697
. collect ( )
@@ -725,7 +721,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
725
721
/// representing the region `r`; return a region referencing it.
726
722
fn canonical_var_for_region (
727
723
& mut self ,
728
- var_kind : CanonicalVarKind < ' tcx > ,
724
+ var_kind : CanonicalVarKind ,
729
725
r : ty:: Region < ' tcx > ,
730
726
) -> ty:: Region < ' tcx > {
731
727
let var = self . canonical_var ( var_kind, r. into ( ) ) ;
@@ -737,14 +733,10 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
737
733
/// if `ty_var` is bound to anything; if so, canonicalize
738
734
/// *that*. Otherwise, create a new canonical variable for
739
735
/// `ty_var`.
740
- fn canonicalize_ty_var (
741
- & mut self ,
742
- var_kind : CanonicalVarKind < ' tcx > ,
743
- ty_var : Ty < ' tcx > ,
744
- ) -> Ty < ' tcx > {
736
+ fn canonicalize_ty_var ( & mut self , var_kind : CanonicalVarKind , ty_var : Ty < ' tcx > ) -> Ty < ' tcx > {
745
737
debug_assert ! ( !self . infcx. is_some_and( |infcx| ty_var != infcx. shallow_resolve( ty_var) ) ) ;
746
738
let var = self . canonical_var ( var_kind, ty_var. into ( ) ) ;
747
- Ty :: new_bound ( self . tcx , self . binder_index , var . into ( ) )
739
+ Ty :: new_bound ( self . tcx , self . binder_index , ty :: BoundTy :: new_anon ( var ) )
748
740
}
749
741
750
742
/// Given a type variable `const_var` of the given kind, first check
@@ -753,7 +745,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
753
745
/// `const_var`.
754
746
fn canonicalize_const_var (
755
747
& mut self ,
756
- var_kind : CanonicalVarKind < ' tcx > ,
748
+ var_kind : CanonicalVarKind ,
757
749
ct_var : ty:: Const < ' tcx > ,
758
750
) -> ty:: Const < ' tcx > {
759
751
debug_assert ! (
0 commit comments