@@ -1034,10 +1034,6 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
1034
1034
1035
1035
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
1036
1036
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 ! ( ) ,
1041
1037
ty:: Param ( param) => match self . list . iter ( ) . position ( |r| r == & param) {
1042
1038
Some ( idx) => self . tcx . mk_ty ( ty:: Placeholder ( ty:: PlaceholderType {
1043
1039
universe : ty:: UniverseIndex :: from_usize ( 0 ) ,
@@ -1053,15 +1049,15 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
1053
1049
} ) )
1054
1050
}
1055
1051
} ,
1056
-
1057
1052
_ => t. super_fold_with ( self ) ,
1058
1053
}
1059
1054
}
1060
1055
1061
1056
fn fold_region ( & mut self , r : Region < ' tcx > ) -> Region < ' tcx > {
1062
1057
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).
1065
1061
ty:: ReEarlyBound ( _re) => match self . named_regions . get ( & _re. def_id ) {
1066
1062
Some ( idx) => {
1067
1063
let br = ty:: BoundRegion {
@@ -1084,6 +1080,39 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
1084
1080
}
1085
1081
}
1086
1082
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
+
1087
1116
/// Used to collect `Placeholder`s.
1088
1117
crate struct PlaceholdersCollector {
1089
1118
universe_index : ty:: UniverseIndex ,
0 commit comments