@@ -138,6 +138,7 @@ pub trait TyDecoder<'a, 'tcx: 'a>: Decoder {
138
138
}
139
139
}
140
140
141
+ #[ inline]
141
142
pub fn decode_cnum < ' a , ' tcx , D > ( decoder : & mut D ) -> Result < CrateNum , D :: Error >
142
143
where D : TyDecoder < ' a , ' tcx > ,
143
144
' tcx : ' a ,
@@ -146,6 +147,7 @@ pub fn decode_cnum<'a, 'tcx, D>(decoder: &mut D) -> Result<CrateNum, D::Error>
146
147
Ok ( decoder. map_encoded_cnum_to_current ( cnum) )
147
148
}
148
149
150
+ #[ inline]
149
151
pub fn decode_ty < ' a , ' tcx , D > ( decoder : & mut D ) -> Result < Ty < ' tcx > , D :: Error >
150
152
where D : TyDecoder < ' a , ' tcx > ,
151
153
' tcx : ' a ,
@@ -165,6 +167,7 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
165
167
}
166
168
}
167
169
170
+ #[ inline]
168
171
pub fn decode_predicates < ' a , ' tcx , D > ( decoder : & mut D )
169
172
-> Result < ty:: GenericPredicates < ' tcx > , D :: Error >
170
173
where D : TyDecoder < ' a , ' tcx > ,
@@ -188,6 +191,7 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
188
191
} )
189
192
}
190
193
194
+ #[ inline]
191
195
pub fn decode_substs < ' a , ' tcx , D > ( decoder : & mut D ) -> Result < & ' tcx Substs < ' tcx > , D :: Error >
192
196
where D : TyDecoder < ' a , ' tcx > ,
193
197
' tcx : ' a ,
@@ -197,13 +201,15 @@ pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result<&'tcx Substs<'tcx>,
197
201
Ok ( tcx. mk_substs ( ( 0 ..len) . map ( |_| Decodable :: decode ( decoder) ) ) ?)
198
202
}
199
203
204
+ #[ inline]
200
205
pub fn decode_region < ' a , ' tcx , D > ( decoder : & mut D ) -> Result < ty:: Region < ' tcx > , D :: Error >
201
206
where D : TyDecoder < ' a , ' tcx > ,
202
207
' tcx : ' a ,
203
208
{
204
209
Ok ( decoder. tcx ( ) . mk_region ( Decodable :: decode ( decoder) ?) )
205
210
}
206
211
212
+ #[ inline]
207
213
pub fn decode_ty_slice < ' a , ' tcx , D > ( decoder : & mut D )
208
214
-> Result < & ' tcx ty:: Slice < Ty < ' tcx > > , D :: Error >
209
215
where D : TyDecoder < ' a , ' tcx > ,
@@ -213,6 +219,7 @@ pub fn decode_ty_slice<'a, 'tcx, D>(decoder: &mut D)
213
219
Ok ( decoder. tcx ( ) . mk_type_list ( ( 0 ..len) . map ( |_| Decodable :: decode ( decoder) ) ) ?)
214
220
}
215
221
222
+ #[ inline]
216
223
pub fn decode_adt_def < ' a , ' tcx , D > ( decoder : & mut D )
217
224
-> Result < & ' tcx ty:: AdtDef , D :: Error >
218
225
where D : TyDecoder < ' a , ' tcx > ,
@@ -222,6 +229,7 @@ pub fn decode_adt_def<'a, 'tcx, D>(decoder: &mut D)
222
229
Ok ( decoder. tcx ( ) . adt_def ( def_id) )
223
230
}
224
231
232
+ #[ inline]
225
233
pub fn decode_existential_predicate_slice < ' a , ' tcx , D > ( decoder : & mut D )
226
234
-> Result < & ' tcx ty:: Slice < ty:: ExistentialPredicate < ' tcx > > , D :: Error >
227
235
where D : TyDecoder < ' a , ' tcx > ,
@@ -232,6 +240,7 @@ pub fn decode_existential_predicate_slice<'a, 'tcx, D>(decoder: &mut D)
232
240
. mk_existential_predicates ( ( 0 ..len) . map ( |_| Decodable :: decode ( decoder) ) ) ?)
233
241
}
234
242
243
+ #[ inline]
235
244
pub fn decode_byte_array < ' a , ' tcx , D > ( decoder : & mut D )
236
245
-> Result < ByteArray < ' tcx > , D :: Error >
237
246
where D : TyDecoder < ' a , ' tcx > ,
@@ -242,10 +251,138 @@ pub fn decode_byte_array<'a, 'tcx, D>(decoder: &mut D)
242
251
} )
243
252
}
244
253
254
+ #[ inline]
245
255
pub fn decode_const < ' a , ' tcx , D > ( decoder : & mut D )
246
256
-> Result < & ' tcx ty:: Const < ' tcx > , D :: Error >
247
257
where D : TyDecoder < ' a , ' tcx > ,
248
258
' tcx : ' a ,
249
259
{
250
260
Ok ( decoder. tcx ( ) . mk_const ( Decodable :: decode ( decoder) ?) )
251
261
}
262
+
263
+ #[ macro_export]
264
+ macro_rules! __impl_decoder_methods {
265
+ ( $( $name: ident -> $ty: ty; ) * ) => {
266
+ $( fn $name( & mut self ) -> Result <$ty, Self :: Error > {
267
+ self . opaque. $name( )
268
+ } ) *
269
+ }
270
+ }
271
+
272
+ #[ macro_export]
273
+ macro_rules! implement_ty_decoder {
274
+ ( $DecoderName: ident <$( $typaram: tt) ,* >) => {
275
+ mod __ty_decoder_impl {
276
+ use super :: $DecoderName;
277
+ use $crate:: ty;
278
+ use $crate:: ty:: codec:: * ;
279
+ use $crate:: ty:: subst:: Substs ;
280
+ use $crate:: hir:: def_id:: { CrateNum } ;
281
+ use $crate:: middle:: const_val:: ByteArray ;
282
+ use rustc_serialize:: { Decoder , SpecializedDecoder } ;
283
+ use std:: borrow:: Cow ;
284
+
285
+ impl <$( $typaram ) ,* > Decoder for $DecoderName<$( $typaram) ,* > {
286
+ type Error = String ;
287
+
288
+ __impl_decoder_methods! {
289
+ read_nil -> ( ) ;
290
+
291
+ read_u128 -> u128 ;
292
+ read_u64 -> u64 ;
293
+ read_u32 -> u32 ;
294
+ read_u16 -> u16 ;
295
+ read_u8 -> u8 ;
296
+ read_usize -> usize ;
297
+
298
+ read_i128 -> i128 ;
299
+ read_i64 -> i64 ;
300
+ read_i32 -> i32 ;
301
+ read_i16 -> i16 ;
302
+ read_i8 -> i8 ;
303
+ read_isize -> isize ;
304
+
305
+ read_bool -> bool ;
306
+ read_f64 -> f64 ;
307
+ read_f32 -> f32 ;
308
+ read_char -> char ;
309
+ read_str -> Cow <str >;
310
+ }
311
+
312
+ fn error( & mut self , err: & str ) -> Self :: Error {
313
+ self . opaque. error( err)
314
+ }
315
+ }
316
+
317
+ // FIXME(#36588) These impls are horribly unsound as they allow
318
+ // the caller to pick any lifetime for 'tcx, including 'static,
319
+ // by using the unspecialized proxies to them.
320
+
321
+ impl <$( $typaram) ,* > SpecializedDecoder <CrateNum > for $DecoderName<$( $typaram) ,* > {
322
+ fn specialized_decode( & mut self ) -> Result <CrateNum , Self :: Error > {
323
+ decode_cnum( self )
324
+ }
325
+ }
326
+
327
+ impl <$( $typaram) ,* > SpecializedDecoder <ty:: Ty <' tcx>> for $DecoderName<$( $typaram) ,* > {
328
+ fn specialized_decode( & mut self ) -> Result <ty:: Ty <' tcx>, Self :: Error > {
329
+ decode_ty( self )
330
+ }
331
+ }
332
+
333
+ impl <$( $typaram) ,* > SpecializedDecoder <ty:: GenericPredicates <' tcx>>
334
+ for $DecoderName<$( $typaram) ,* > {
335
+ fn specialized_decode( & mut self ) -> Result <ty:: GenericPredicates <' tcx>, Self :: Error > {
336
+ decode_predicates( self )
337
+ }
338
+ }
339
+
340
+ impl <$( $typaram) ,* > SpecializedDecoder <& ' tcx Substs <' tcx>> for $DecoderName<$( $typaram) ,* > {
341
+ fn specialized_decode( & mut self ) -> Result <& ' tcx Substs <' tcx>, Self :: Error > {
342
+ decode_substs( self )
343
+ }
344
+ }
345
+
346
+ impl <$( $typaram) ,* > SpecializedDecoder <ty:: Region <' tcx>> for $DecoderName<$( $typaram) ,* > {
347
+ fn specialized_decode( & mut self ) -> Result <ty:: Region <' tcx>, Self :: Error > {
348
+ decode_region( self )
349
+ }
350
+ }
351
+
352
+ impl <$( $typaram) ,* > SpecializedDecoder <& ' tcx ty:: Slice <ty:: Ty <' tcx>>>
353
+ for $DecoderName<$( $typaram) ,* > {
354
+ fn specialized_decode( & mut self ) -> Result <& ' tcx ty:: Slice <ty:: Ty <' tcx>>, Self :: Error > {
355
+ decode_ty_slice( self )
356
+ }
357
+ }
358
+
359
+ impl <$( $typaram) ,* > SpecializedDecoder <& ' tcx ty:: AdtDef > for $DecoderName<$( $typaram) ,* > {
360
+ fn specialized_decode( & mut self ) -> Result <& ' tcx ty:: AdtDef , Self :: Error > {
361
+ decode_adt_def( self )
362
+ }
363
+ }
364
+
365
+ impl <$( $typaram) ,* > SpecializedDecoder <& ' tcx ty:: Slice <ty:: ExistentialPredicate <' tcx>>>
366
+ for $DecoderName<$( $typaram) ,* > {
367
+ fn specialized_decode( & mut self )
368
+ -> Result <& ' tcx ty:: Slice <ty:: ExistentialPredicate <' tcx>>, Self :: Error > {
369
+ decode_existential_predicate_slice( self )
370
+ }
371
+ }
372
+
373
+ impl <$( $typaram) ,* > SpecializedDecoder <ByteArray <' tcx>> for $DecoderName<$( $typaram) ,* > {
374
+ fn specialized_decode( & mut self ) -> Result <ByteArray <' tcx>, Self :: Error > {
375
+ decode_byte_array( self )
376
+ }
377
+ }
378
+
379
+ impl <$( $typaram) ,* > SpecializedDecoder <& ' tcx $crate:: ty:: Const <' tcx>>
380
+ for $DecoderName<$( $typaram) ,* > {
381
+ fn specialized_decode( & mut self ) -> Result <& ' tcx ty:: Const <' tcx>, Self :: Error > {
382
+ decode_const( self )
383
+ }
384
+ }
385
+ }
386
+ }
387
+ }
388
+
0 commit comments