@@ -13,7 +13,7 @@ use region_constraints::{
1313pub use relate:: combine:: { CombineFields , PredicateEmittingRelation } ;
1414pub use relate:: StructurallyRelateAliases ;
1515use rustc_data_structures:: captures:: Captures ;
16- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
16+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
1717use rustc_data_structures:: sync:: Lrc ;
1818use rustc_data_structures:: undo_log:: Rollback ;
1919use rustc_data_structures:: unify as ut;
@@ -1318,38 +1318,36 @@ impl<'tcx> InferCtxt<'tcx> {
13181318 return inner;
13191319 }
13201320
1321- struct ToFreshVars < ' a , ' tcx > {
1322- infcx : & ' a InferCtxt < ' tcx > ,
1323- span : Span ,
1324- lbrct : BoundRegionConversionTime ,
1325- map : FxHashMap < ty:: BoundVar , ty:: GenericArg < ' tcx > > ,
1321+ let bound_vars = value. bound_vars ( ) ;
1322+ let mut args = Vec :: with_capacity ( bound_vars. len ( ) ) ;
1323+
1324+ for bound_var_kind in bound_vars {
1325+ let arg: ty:: GenericArg < ' _ > = match bound_var_kind {
1326+ ty:: BoundVariableKind :: Ty ( _) => self . next_ty_var ( span) . into ( ) ,
1327+ ty:: BoundVariableKind :: Region ( br) => {
1328+ self . next_region_var ( BoundRegion ( span, br, lbrct) ) . into ( )
1329+ }
1330+ ty:: BoundVariableKind :: Const => self . next_const_var ( span) . into ( ) ,
1331+ } ;
1332+ args. push ( arg) ;
1333+ }
1334+
1335+ struct ToFreshVars < ' tcx > {
1336+ args : Vec < ty:: GenericArg < ' tcx > > ,
13261337 }
13271338
1328- impl < ' tcx > BoundVarReplacerDelegate < ' tcx > for ToFreshVars < ' _ , ' tcx > {
1339+ impl < ' tcx > BoundVarReplacerDelegate < ' tcx > for ToFreshVars < ' tcx > {
13291340 fn replace_region ( & mut self , br : ty:: BoundRegion ) -> ty:: Region < ' tcx > {
1330- self . map
1331- . entry ( br. var )
1332- . or_insert_with ( || {
1333- self . infcx
1334- . next_region_var ( BoundRegion ( self . span , br. kind , self . lbrct ) )
1335- . into ( )
1336- } )
1337- . expect_region ( )
1341+ self . args [ br. var . index ( ) ] . expect_region ( )
13381342 }
13391343 fn replace_ty ( & mut self , bt : ty:: BoundTy ) -> Ty < ' tcx > {
1340- self . map
1341- . entry ( bt. var )
1342- . or_insert_with ( || self . infcx . next_ty_var ( self . span ) . into ( ) )
1343- . expect_ty ( )
1344+ self . args [ bt. var . index ( ) ] . expect_ty ( )
13441345 }
13451346 fn replace_const ( & mut self , bv : ty:: BoundVar ) -> ty:: Const < ' tcx > {
1346- self . map
1347- . entry ( bv)
1348- . or_insert_with ( || self . infcx . next_const_var ( self . span ) . into ( ) )
1349- . expect_const ( )
1347+ self . args [ bv. index ( ) ] . expect_const ( )
13501348 }
13511349 }
1352- let delegate = ToFreshVars { infcx : self , span , lbrct , map : Default :: default ( ) } ;
1350+ let delegate = ToFreshVars { args } ;
13531351 self . tcx . replace_bound_vars_uncached ( value, delegate)
13541352 }
13551353
0 commit comments