@@ -1075,6 +1075,10 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
1075
1075
}
1076
1076
1077
1077
trait rbml_decoder_decoder_helpers < ' tcx > {
1078
+ fn read_ty_encoded < ' a , ' b , F , R > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ,
1079
+ f : F ) -> R
1080
+ where F : for < ' x > FnOnce ( & mut tydecode:: TyDecoder < ' x , ' tcx > ) -> R ;
1081
+
1078
1082
fn read_ty < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Ty < ' tcx > ;
1079
1083
fn read_tys < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > ) -> Vec < Ty < ' tcx > > ;
1080
1084
fn read_trait_ref < ' a , ' b > ( & mut self , dcx : & DecodeContext < ' a , ' b , ' tcx > )
@@ -1123,14 +1127,14 @@ trait rbml_decoder_decoder_helpers<'tcx> {
1123
1127
1124
1128
impl < ' a , ' tcx > rbml_decoder_decoder_helpers < ' tcx > for reader:: Decoder < ' a > {
1125
1129
fn read_ty_nodcx ( & mut self ,
1126
- tcx : & ty:: ctxt < ' tcx > , cdata : & cstore:: crate_metadata ) -> Ty < ' tcx > {
1130
+ tcx : & ty:: ctxt < ' tcx > ,
1131
+ cdata : & cstore:: crate_metadata )
1132
+ -> Ty < ' tcx > {
1127
1133
self . read_opaque ( |_, doc| {
1128
- Ok ( tydecode:: parse_ty_data (
1129
- doc. data ,
1130
- cdata. cnum ,
1131
- doc. start ,
1132
- tcx,
1133
- |_, id| decoder:: translate_def_id ( cdata, id) ) )
1134
+ Ok (
1135
+ tydecode:: TyDecoder :: with_doc ( tcx, cdata. cnum , doc,
1136
+ & mut |_, id| decoder:: translate_def_id ( cdata, id) )
1137
+ . parse_ty ( ) )
1134
1138
} ) . unwrap ( )
1135
1139
}
1136
1140
@@ -1149,32 +1153,22 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1149
1153
-> subst:: Substs < ' tcx >
1150
1154
{
1151
1155
self . read_opaque ( |_, doc| {
1152
- Ok ( tydecode:: parse_substs_data (
1153
- doc. data ,
1154
- cdata. cnum ,
1155
- doc. start ,
1156
- tcx,
1157
- |_, id| decoder:: translate_def_id ( cdata, id) ) )
1156
+ Ok (
1157
+ tydecode:: TyDecoder :: with_doc ( tcx, cdata. cnum , doc,
1158
+ & mut |_, id| decoder:: translate_def_id ( cdata, id) )
1159
+ . parse_substs ( ) )
1158
1160
} ) . unwrap ( )
1159
1161
}
1160
1162
1161
- fn read_ty < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > ) -> Ty < ' tcx > {
1162
- // Note: regions types embed local node ids. In principle, we
1163
- // should translate these node ids into the new decode
1164
- // context. However, we do not bother, because region types
1165
- // are not used during trans.
1166
-
1163
+ fn read_ty_encoded < ' b , ' c , F , R > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > , op : F ) -> R
1164
+ where F : for < ' x > FnOnce ( & mut tydecode:: TyDecoder < ' x , ' tcx > ) -> R
1165
+ {
1167
1166
return self . read_opaque ( |this, doc| {
1168
- debug ! ( "read_ty({})" , type_string( doc) ) ;
1169
-
1170
- let ty = tydecode:: parse_ty_data (
1171
- doc. data ,
1172
- dcx. cdata . cnum ,
1173
- doc. start ,
1174
- dcx. tcx ,
1175
- |s, a| this. convert_def_id ( dcx, s, a) ) ;
1176
-
1177
- Ok ( ty)
1167
+ debug ! ( "read_ty_encoded({})" , type_string( doc) ) ;
1168
+ Ok ( op (
1169
+ & mut tydecode:: TyDecoder :: with_doc (
1170
+ dcx. tcx , dcx. cdata . cnum , doc,
1171
+ & mut |s, a| this. convert_def_id ( dcx, s, a) ) ) )
1178
1172
} ) . unwrap ( ) ;
1179
1173
1180
1174
fn type_string ( doc : rbml:: Doc ) -> String {
@@ -1186,56 +1180,39 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1186
1180
}
1187
1181
}
1188
1182
1183
+ fn read_ty < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > ) -> Ty < ' tcx > {
1184
+ // Note: regions types embed local node ids. In principle, we
1185
+ // should translate these node ids into the new decode
1186
+ // context. However, we do not bother, because region types
1187
+ // are not used during trans.
1188
+
1189
+ return self . read_ty_encoded ( dcx, |decoder| decoder. parse_ty ( ) ) ;
1190
+ }
1191
+
1189
1192
fn read_tys < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1190
1193
-> Vec < Ty < ' tcx > > {
1191
1194
self . read_to_vec ( |this| Ok ( this. read_ty ( dcx) ) ) . unwrap ( ) . into_iter ( ) . collect ( )
1192
1195
}
1193
1196
1194
1197
fn read_trait_ref < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1195
1198
-> ty:: TraitRef < ' tcx > {
1196
- self . read_opaque ( |this, doc| {
1197
- let ty = tydecode:: parse_trait_ref_data (
1198
- doc. data ,
1199
- dcx. cdata . cnum ,
1200
- doc. start ,
1201
- dcx. tcx ,
1202
- |s, a| this. convert_def_id ( dcx, s, a) ) ;
1203
- Ok ( ty)
1204
- } ) . unwrap ( )
1199
+ self . read_ty_encoded ( dcx, |decoder| decoder. parse_trait_ref ( ) )
1205
1200
}
1206
1201
1207
1202
fn read_poly_trait_ref < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1208
1203
-> ty:: PolyTraitRef < ' tcx > {
1209
- ty:: Binder ( self . read_opaque ( |this, doc| {
1210
- let ty = tydecode:: parse_trait_ref_data (
1211
- doc. data ,
1212
- dcx. cdata . cnum ,
1213
- doc. start ,
1214
- dcx. tcx ,
1215
- |s, a| this. convert_def_id ( dcx, s, a) ) ;
1216
- Ok ( ty)
1217
- } ) . unwrap ( ) )
1204
+ ty:: Binder ( self . read_ty_encoded ( dcx, |decoder| decoder. parse_trait_ref ( ) ) )
1218
1205
}
1219
1206
1220
1207
fn read_type_param_def < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1221
1208
-> ty:: TypeParameterDef < ' tcx > {
1222
- self . read_opaque ( |this, doc| {
1223
- Ok ( tydecode:: parse_type_param_def_data (
1224
- doc. data ,
1225
- doc. start ,
1226
- dcx. cdata . cnum ,
1227
- dcx. tcx ,
1228
- |s, a| this. convert_def_id ( dcx, s, a) ) )
1229
- } ) . unwrap ( )
1209
+ self . read_ty_encoded ( dcx, |decoder| decoder. parse_type_param_def ( ) )
1230
1210
}
1231
1211
1232
1212
fn read_predicate < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1233
1213
-> ty:: Predicate < ' tcx >
1234
1214
{
1235
- self . read_opaque ( |this, doc| {
1236
- Ok ( tydecode:: parse_predicate_data ( doc. data , doc. start , dcx. cdata . cnum , dcx. tcx ,
1237
- |s, a| this. convert_def_id ( dcx, s, a) ) )
1238
- } ) . unwrap ( )
1215
+ self . read_ty_encoded ( dcx, |decoder| decoder. parse_predicate ( ) )
1239
1216
}
1240
1217
1241
1218
fn read_type_scheme < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
@@ -1269,13 +1246,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1269
1246
fn read_existential_bounds < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1270
1247
-> ty:: ExistentialBounds < ' tcx >
1271
1248
{
1272
- self . read_opaque ( |this, doc| {
1273
- Ok ( tydecode:: parse_existential_bounds_data ( doc. data ,
1274
- dcx. cdata . cnum ,
1275
- doc. start ,
1276
- dcx. tcx ,
1277
- |s, a| this. convert_def_id ( dcx, s, a) ) )
1278
- } ) . unwrap ( )
1249
+ self . read_ty_encoded ( dcx, |decoder| decoder. parse_existential_bounds ( ) )
1279
1250
}
1280
1251
1281
1252
fn read_substs < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
@@ -1380,14 +1351,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
1380
1351
fn read_closure_ty < ' b , ' c > ( & mut self , dcx : & DecodeContext < ' b , ' c , ' tcx > )
1381
1352
-> ty:: ClosureTy < ' tcx >
1382
1353
{
1383
- self . read_opaque ( |this, doc| {
1384
- Ok ( tydecode:: parse_ty_closure_data (
1385
- doc. data ,
1386
- dcx. cdata . cnum ,
1387
- doc. start ,
1388
- dcx. tcx ,
1389
- |s, a| this. convert_def_id ( dcx, s, a) ) )
1390
- } ) . unwrap ( )
1354
+ self . read_ty_encoded ( dcx, |decoder| decoder. parse_closure_ty ( ) )
1391
1355
}
1392
1356
1393
1357
/// Converts a def-id that appears in a type. The correct
0 commit comments