@@ -2014,31 +2014,54 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
2014
2014
tcx : TyCtxt < ' tcx > ,
2015
2015
substs : SubstsRef < ' tcx > ,
2016
2016
) -> SubstsRef < ' tcx > {
2017
- tcx. mk_substs ( substs. iter ( ) . enumerate ( ) . map ( |( idx, arg) | {
2018
- match arg. unpack ( ) {
2019
- GenericArgKind :: Type ( _) if arg. has_non_region_param ( ) || arg. has_non_region_infer ( ) => {
2020
- tcx. mk_ty ( ty:: Placeholder ( ty:: PlaceholderType {
2017
+ struct ReplaceParamAndInferWithPlaceholder < ' tcx > {
2018
+ tcx : TyCtxt < ' tcx > ,
2019
+ idx : usize ,
2020
+ }
2021
+
2022
+ impl < ' tcx > TypeFolder < ' tcx > for ReplaceParamAndInferWithPlaceholder < ' tcx > {
2023
+ fn tcx ( & self ) -> TyCtxt < ' tcx > {
2024
+ self . tcx
2025
+ }
2026
+
2027
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
2028
+ if let ty:: Infer ( _) = t. kind ( ) {
2029
+ self . tcx . mk_ty ( ty:: Placeholder ( ty:: PlaceholderType {
2021
2030
universe : ty:: UniverseIndex :: ROOT ,
2022
- name : ty:: BoundVar :: from_usize ( idx) ,
2031
+ name : ty:: BoundVar :: from_usize ( {
2032
+ let idx = self . idx ;
2033
+ self . idx += 1 ;
2034
+ idx
2035
+ } ) ,
2023
2036
} ) )
2024
- . into ( )
2037
+ } else {
2038
+ t. super_fold_with ( self )
2025
2039
}
2026
- GenericArgKind :: Const ( ct) if ct. has_non_region_infer ( ) || ct. has_non_region_param ( ) => {
2027
- let ty = ct. ty ( ) ;
2028
- // If the type references param or infer, replace that too...
2040
+ }
2041
+
2042
+ fn fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
2043
+ if let ty:: ConstKind :: Infer ( _) = c. kind ( ) {
2044
+ let ty = c. ty ( ) ;
2045
+ // If the type references param or infer then ICE ICE ICE
2029
2046
if ty. has_non_region_param ( ) || ty. has_non_region_infer ( ) {
2030
- bug ! ( "const `{ct }`'s type should not reference params or types" ) ;
2047
+ bug ! ( "const `{c }`'s type should not reference params or types" ) ;
2031
2048
}
2032
- tcx. mk_const (
2049
+ self . tcx . mk_const (
2033
2050
ty:: PlaceholderConst {
2034
2051
universe : ty:: UniverseIndex :: ROOT ,
2035
- name : ty:: BoundVar :: from_usize ( idx) ,
2052
+ name : ty:: BoundVar :: from_usize ( {
2053
+ let idx = self . idx ;
2054
+ self . idx += 1 ;
2055
+ idx
2056
+ } ) ,
2036
2057
} ,
2037
2058
ty,
2038
2059
)
2039
- . into ( )
2060
+ } else {
2061
+ c. super_fold_with ( self )
2040
2062
}
2041
- _ => arg,
2042
2063
}
2043
- } ) )
2064
+ }
2065
+
2066
+ substs. fold_with ( & mut ReplaceParamAndInferWithPlaceholder { tcx, idx : 0 } )
2044
2067
}
0 commit comments