1-
21use rustc_hash:: FxHashMap ;
32use rustc_index:: Idx ;
4- use rustc_type_ir:: inherent:: { Const as _, IntoKind as _, Region as _, SliceLike , Ty as _} ;
53use rustc_type_ir:: InferTy :: { self , FloatVar , IntVar , TyVar } ;
6- use rustc_type_ir:: { BoundVar , CanonicalQueryInput , CanonicalTyVarKind , DebruijnIndex , Flags , InferConst , RegionKind , TypeFlags , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt , UniverseIndex } ;
4+ use rustc_type_ir:: inherent:: { Const as _, IntoKind as _, Region as _, SliceLike , Ty as _} ;
5+ use rustc_type_ir:: {
6+ BoundVar , CanonicalQueryInput , CanonicalTyVarKind , DebruijnIndex , Flags , InferConst ,
7+ RegionKind , TypeFlags , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitableExt ,
8+ UniverseIndex ,
9+ } ;
710use smallvec:: SmallVec ;
811use tracing:: debug;
912
1013use crate :: next_solver:: infer:: InferCtxt ;
11- use crate :: next_solver:: { Binder , BoundRegion , BoundRegionKind , BoundTy , Canonical , CanonicalVarKind , CanonicalVars , Const , ConstKind , DbInterner , GenericArg , ParamEnvAnd , Placeholder , Region , Ty , TyKind } ;
14+ use crate :: next_solver:: {
15+ Binder , BoundRegion , BoundRegionKind , BoundTy , Canonical , CanonicalVarKind , CanonicalVars ,
16+ Const , ConstKind , DbInterner , GenericArg , ParamEnvAnd , Placeholder , Region , Ty , TyKind ,
17+ } ;
1218
1319/// When we canonicalize a value to form a query, we wind up replacing
1420/// various parts of it with canonical variables. This struct stores
@@ -180,12 +186,14 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
180186 } ;
181187
182188 match r. kind ( ) {
183- RegionKind :: ReLateParam ( _) | RegionKind :: ReErased | RegionKind :: ReStatic | RegionKind :: ReEarlyParam ( ..) | RegionKind :: ReError ( ..) => r,
189+ RegionKind :: ReLateParam ( _)
190+ | RegionKind :: ReErased
191+ | RegionKind :: ReStatic
192+ | RegionKind :: ReEarlyParam ( ..)
193+ | RegionKind :: ReError ( ..) => r,
184194
185- RegionKind :: RePlaceholder ( placeholder) => canonicalizer. canonical_var_for_region (
186- CanonicalVarKind :: PlaceholderRegion ( placeholder) ,
187- r,
188- ) ,
195+ RegionKind :: RePlaceholder ( placeholder) => canonicalizer
196+ . canonical_var_for_region ( CanonicalVarKind :: PlaceholderRegion ( placeholder) , r) ,
189197
190198 RegionKind :: ReVar ( vid) => {
191199 let universe = infcx
@@ -194,10 +202,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
194202 . unwrap_region_constraints ( )
195203 . probe_value ( vid)
196204 . unwrap_err ( ) ;
197- canonicalizer. canonical_var_for_region (
198- CanonicalVarKind :: Region ( universe) ,
199- r,
200- )
205+ canonicalizer. canonical_var_for_region ( CanonicalVarKind :: Region ( universe) , r)
201206 }
202207
203208 _ => {
@@ -384,36 +389,29 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
384389 if nt != t {
385390 self . fold_ty ( nt)
386391 } else {
387- self . canonicalize_ty_var (
388- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) ,
389- t,
390- )
392+ self . canonicalize_ty_var ( CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) , t)
391393 }
392394 }
393395 TyKind :: Infer ( FloatVar ( vid) ) => {
394396 let nt = self . infcx . unwrap ( ) . opportunistic_resolve_float_var ( vid) ;
395397 if nt != t {
396398 self . fold_ty ( nt)
397399 } else {
398- self . canonicalize_ty_var (
399- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) ,
400- t,
401- )
400+ self . canonicalize_ty_var ( CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) , t)
402401 }
403402 }
404403
405- TyKind :: Infer ( InferTy :: FreshTy ( _) | InferTy :: FreshIntTy ( _) | InferTy :: FreshFloatTy ( _) ) => {
404+ TyKind :: Infer (
405+ InferTy :: FreshTy ( _) | InferTy :: FreshIntTy ( _) | InferTy :: FreshFloatTy ( _) ,
406+ ) => {
406407 panic ! ( "encountered a fresh type during canonicalization" )
407408 }
408409
409410 TyKind :: Placeholder ( mut placeholder) => {
410411 if !self . canonicalize_mode . preserve_universes ( ) {
411412 placeholder. universe = UniverseIndex :: ROOT ;
412413 }
413- self . canonicalize_ty_var (
414- CanonicalVarKind :: PlaceholderTy ( placeholder) ,
415- t,
416- )
414+ self . canonicalize_ty_var ( CanonicalVarKind :: PlaceholderTy ( placeholder) , t)
417415 }
418416
419417 TyKind :: Bound ( debruijn, _) => {
@@ -485,10 +483,7 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
485483 // FIXME: perf problem described in #55921.
486484 ui = UniverseIndex :: ROOT ;
487485 }
488- return self . canonicalize_const_var (
489- CanonicalVarKind :: Const ( ui) ,
490- ct,
491- ) ;
486+ return self . canonicalize_const_var ( CanonicalVarKind :: Const ( ui) , ct) ;
492487 }
493488 }
494489 }
@@ -503,10 +498,8 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
503498 }
504499 }
505500 ConstKind :: Placeholder ( placeholder) => {
506- return self . canonicalize_const_var (
507- CanonicalVarKind :: PlaceholderConst ( placeholder) ,
508- ct,
509- ) ;
501+ return self
502+ . canonicalize_const_var ( CanonicalVarKind :: PlaceholderConst ( placeholder) , ct) ;
510503 }
511504 _ => { }
512505 }
@@ -596,7 +589,8 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
596589 // anymore.
597590 debug_assert ! ( !out_value. has_infer( ) && !out_value. has_placeholders( ) ) ;
598591
599- let canonical_variables = CanonicalVars :: new_from_iter ( tcx, canonicalizer. universe_canonicalized_variables ( ) ) ;
592+ let canonical_variables =
593+ CanonicalVars :: new_from_iter ( tcx, canonicalizer. universe_canonicalized_variables ( ) ) ;
600594
601595 let max_universe = canonical_variables
602596 . iter ( )
@@ -690,15 +684,11 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
690684 self . variables
691685 . iter ( )
692686 . map ( |v| match * v {
693- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
694- * v
695- }
687+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => * v,
696688 CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( u) ) => {
697689 CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( reverse_universe_map[ & u] ) )
698690 }
699- CanonicalVarKind :: Region ( u) => {
700- CanonicalVarKind :: Region ( reverse_universe_map[ & u] )
701- }
691+ CanonicalVarKind :: Region ( u) => CanonicalVarKind :: Region ( reverse_universe_map[ & u] ) ,
702692 CanonicalVarKind :: Const ( u) => CanonicalVarKind :: Const ( reverse_universe_map[ & u] ) ,
703693 CanonicalVarKind :: PlaceholderTy ( placeholder) => {
704694 CanonicalVarKind :: PlaceholderTy ( Placeholder {
@@ -735,14 +725,8 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
735725 ///
736726 /// (This works because unification never fails -- and hence trait
737727 /// selection is never affected -- due to a universe mismatch.)
738- fn canonical_var_for_region_in_root_universe (
739- & mut self ,
740- r : Region < ' db > ,
741- ) -> Region < ' db > {
742- self . canonical_var_for_region (
743- CanonicalVarKind :: Region ( UniverseIndex :: ROOT ) ,
744- r,
745- )
728+ fn canonical_var_for_region_in_root_universe ( & mut self , r : Region < ' db > ) -> Region < ' db > {
729+ self . canonical_var_for_region ( CanonicalVarKind :: Region ( UniverseIndex :: ROOT ) , r)
746730 }
747731
748732 /// Creates a canonical variable (with the given `info`)
@@ -764,7 +748,11 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
764748 fn canonicalize_ty_var ( & mut self , info : CanonicalVarKind < ' db > , ty_var : Ty < ' db > ) -> Ty < ' db > {
765749 debug_assert ! ( !self . infcx. is_some_and( |infcx| ty_var != infcx. shallow_resolve( ty_var) ) ) ;
766750 let var = self . canonical_var ( info, ty_var. into ( ) ) ;
767- Ty :: new_bound ( self . tcx , self . binder_index , BoundTy { kind : crate :: next_solver:: BoundTyKind :: Anon , var } )
751+ Ty :: new_bound (
752+ self . tcx ,
753+ self . binder_index ,
754+ BoundTy { kind : crate :: next_solver:: BoundTyKind :: Anon , var } ,
755+ )
768756 }
769757
770758 /// Given a type variable `const_var` of the given kind, first check
0 commit comments