@@ -2014,31 +2014,54 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20142014 tcx : TyCtxt < ' tcx > ,
20152015 substs : SubstsRef < ' tcx > ,
20162016) -> 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 {
20212030 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+ } ) ,
20232036 } ) )
2024- . into ( )
2037+ } else {
2038+ t. super_fold_with ( self )
20252039 }
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
20292046 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" ) ;
20312048 }
2032- tcx. mk_const (
2049+ self . tcx . mk_const (
20332050 ty:: PlaceholderConst {
20342051 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+ } ) ,
20362057 } ,
20372058 ty,
20382059 )
2039- . into ( )
2060+ } else {
2061+ c. super_fold_with ( self )
20402062 }
2041- _ => arg,
20422063 }
2043- } ) )
2064+ }
2065+
2066+ substs. fold_with ( & mut ReplaceParamAndInferWithPlaceholder { tcx, idx : 0 } )
20442067}
0 commit comments