@@ -23,6 +23,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
23
23
use rustc_middle:: traits:: select;
24
24
use rustc_middle:: ty:: abstract_const:: { AbstractConst , FailureKind } ;
25
25
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
26
+ use rustc_middle:: ty:: fold:: BoundVarReplacerDelegate ;
26
27
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
27
28
use rustc_middle:: ty:: relate:: RelateResult ;
28
29
use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , InternalSubsts , SubstsRef } ;
@@ -1564,32 +1565,56 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1564
1565
return inner;
1565
1566
}
1566
1567
1567
- let mut region_map = FxHashMap :: default ( ) ;
1568
- let fld_r = | br : ty :: BoundRegion | {
1569
- * region_map
1570
- . entry ( br )
1571
- . or_insert_with ( || self . next_region_var ( LateBoundRegion ( span , br . kind , lbrct ) ) )
1572
- } ;
1568
+ struct ToFreshVars < ' a , ' tcx > {
1569
+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
1570
+ span : Span ,
1571
+ lbrct : LateBoundRegionConversionTime ,
1572
+ map : FxHashMap < ty :: BoundVar , ty :: GenericArg < ' tcx > > ,
1573
+ }
1573
1574
1574
- let mut ty_map = FxHashMap :: default ( ) ;
1575
- let fld_t = |bt : ty:: BoundTy | {
1576
- * ty_map. entry ( bt) . or_insert_with ( || {
1577
- self . next_ty_var ( TypeVariableOrigin {
1578
- kind : TypeVariableOriginKind :: MiscVariable ,
1579
- span,
1580
- } )
1581
- } )
1582
- } ;
1583
- let mut ct_map = FxHashMap :: default ( ) ;
1584
- let fld_c = |bc : ty:: BoundVar , ty| {
1585
- * ct_map. entry ( bc) . or_insert_with ( || {
1586
- self . next_const_var (
1587
- ty,
1588
- ConstVariableOrigin { kind : ConstVariableOriginKind :: MiscVariable , span } ,
1589
- )
1590
- } )
1591
- } ;
1592
- self . tcx . replace_bound_vars_uncached ( value, fld_r, fld_t, fld_c)
1575
+ impl < ' tcx > BoundVarReplacerDelegate < ' tcx > for ToFreshVars < ' _ , ' tcx > {
1576
+ fn replace_region ( & mut self , br : ty:: BoundRegion ) -> ty:: Region < ' tcx > {
1577
+ self . map
1578
+ . entry ( br. var )
1579
+ . or_insert_with ( || {
1580
+ self . infcx
1581
+ . next_region_var ( LateBoundRegion ( self . span , br. kind , self . lbrct ) )
1582
+ . into ( )
1583
+ } )
1584
+ . expect_region ( )
1585
+ }
1586
+ fn replace_ty ( & mut self , bt : ty:: BoundTy ) -> Ty < ' tcx > {
1587
+ self . map
1588
+ . entry ( bt. var )
1589
+ . or_insert_with ( || {
1590
+ self . infcx
1591
+ . next_ty_var ( TypeVariableOrigin {
1592
+ kind : TypeVariableOriginKind :: MiscVariable ,
1593
+ span : self . span ,
1594
+ } )
1595
+ . into ( )
1596
+ } )
1597
+ . expect_ty ( )
1598
+ }
1599
+ fn replace_const ( & mut self , bv : ty:: BoundVar , ty : Ty < ' tcx > ) -> ty:: Const < ' tcx > {
1600
+ self . map
1601
+ . entry ( bv)
1602
+ . or_insert_with ( || {
1603
+ self . infcx
1604
+ . next_const_var (
1605
+ ty,
1606
+ ConstVariableOrigin {
1607
+ kind : ConstVariableOriginKind :: MiscVariable ,
1608
+ span : self . span ,
1609
+ } ,
1610
+ )
1611
+ . into ( )
1612
+ } )
1613
+ . expect_const ( )
1614
+ }
1615
+ }
1616
+ let delegate = ToFreshVars { infcx : self , span, lbrct, map : Default :: default ( ) } ;
1617
+ self . tcx . replace_bound_vars_uncached ( value, delegate)
1593
1618
}
1594
1619
1595
1620
/// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method.
0 commit comments