@@ -1034,10 +1034,6 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
10341034
10351035 fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
10361036 match * t. kind ( ) {
1037- // FIXME(chalk): currently we convert params to placeholders starting at
1038- // index `0`. To support placeholders, we'll actually need to do a
1039- // first pass to collect placeholders. Then we can insert params after.
1040- ty:: Placeholder ( _) => unimplemented ! ( ) ,
10411037 ty:: Param ( param) => match self . list . iter ( ) . position ( |r| r == & param) {
10421038 Some ( idx) => self . tcx . mk_ty ( ty:: Placeholder ( ty:: PlaceholderType {
10431039 universe : ty:: UniverseIndex :: from_usize ( 0 ) ,
@@ -1053,15 +1049,15 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
10531049 } ) )
10541050 }
10551051 } ,
1056-
10571052 _ => t. super_fold_with ( self ) ,
10581053 }
10591054 }
10601055
10611056 fn fold_region ( & mut self , r : Region < ' tcx > ) -> Region < ' tcx > {
10621057 match r {
1063- // FIXME(chalk) - jackh726 - this currently isn't hit in any tests.
1064- // This covers any region variables in a goal, right?
1058+ // FIXME(chalk) - jackh726 - this currently isn't hit in any tests,
1059+ // since canonicalization will already change these to canonical
1060+ // variables (ty::ReLateBound).
10651061 ty:: ReEarlyBound ( _re) => match self . named_regions . get ( & _re. def_id ) {
10661062 Some ( idx) => {
10671063 let br = ty:: BoundRegion {
@@ -1084,6 +1080,39 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
10841080 }
10851081}
10861082
1083+ crate struct ReverseParamsSubstitutor < ' tcx > {
1084+ tcx : TyCtxt < ' tcx > ,
1085+ params : rustc_data_structures:: fx:: FxHashMap < usize , rustc_middle:: ty:: ParamTy > ,
1086+ }
1087+
1088+ impl < ' tcx > ReverseParamsSubstitutor < ' tcx > {
1089+ crate fn new (
1090+ tcx : TyCtxt < ' tcx > ,
1091+ params : rustc_data_structures:: fx:: FxHashMap < usize , rustc_middle:: ty:: ParamTy > ,
1092+ ) -> Self {
1093+ Self { tcx, params }
1094+ }
1095+ }
1096+
1097+ impl < ' tcx > TypeFolder < ' tcx > for ReverseParamsSubstitutor < ' tcx > {
1098+ fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
1099+ self . tcx
1100+ }
1101+
1102+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1103+ match * t. kind ( ) {
1104+ ty:: Placeholder ( ty:: PlaceholderType { universe : ty:: UniverseIndex :: ROOT , name } ) => {
1105+ match self . params . get ( & name. as_usize ( ) ) {
1106+ Some ( param) => self . tcx . mk_ty ( ty:: Param ( * param) ) ,
1107+ None => t,
1108+ }
1109+ }
1110+
1111+ _ => t. super_fold_with ( self ) ,
1112+ }
1113+ }
1114+ }
1115+
10871116/// Used to collect `Placeholder`s.
10881117crate struct PlaceholdersCollector {
10891118 universe_index : ty:: UniverseIndex ,
0 commit comments