@@ -120,9 +120,9 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
120
120
}
121
121
}
122
122
123
- impl < ' tcx , E : TyEncoder < ' tcx > > Encodable < E > for ty:: PredicateKind < ' tcx > {
123
+ impl < ' tcx , E : TyEncoder < ' tcx > > Encodable < E > for ty:: Binder < ty :: PredicateKind < ' tcx > > {
124
124
fn encode ( & self , e : & mut E ) -> Result < ( ) , E :: Error > {
125
- encode_with_shorthand ( e, self , TyEncoder :: predicate_shorthands)
125
+ encode_with_shorthand ( e, & self . skip_binder ( ) , TyEncoder :: predicate_shorthands)
126
126
}
127
127
}
128
128
@@ -226,18 +226,18 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
226
226
}
227
227
}
228
228
229
- impl < ' tcx , D : TyDecoder < ' tcx > > Decodable < D > for ty:: PredicateKind < ' tcx > {
230
- fn decode ( decoder : & mut D ) -> Result < ty:: PredicateKind < ' tcx > , D :: Error > {
229
+ impl < ' tcx , D : TyDecoder < ' tcx > > Decodable < D > for ty:: Binder < ty :: PredicateKind < ' tcx > > {
230
+ fn decode ( decoder : & mut D ) -> Result < ty:: Binder < ty :: PredicateKind < ' tcx > > , D :: Error > {
231
231
// Handle shorthands first, if we have an usize > 0x80.
232
- if decoder. positioned_at_shorthand ( ) {
232
+ Ok ( ty :: Binder :: bind ( if decoder. positioned_at_shorthand ( ) {
233
233
let pos = decoder. read_usize ( ) ?;
234
234
assert ! ( pos >= SHORTHAND_OFFSET ) ;
235
235
let shorthand = pos - SHORTHAND_OFFSET ;
236
236
237
- decoder. with_position ( shorthand, ty:: PredicateKind :: decode)
237
+ decoder. with_position ( shorthand, ty:: PredicateKind :: decode) ?
238
238
} else {
239
- Ok ( ty:: PredicateKind :: decode ( decoder) ?)
240
- }
239
+ ty:: PredicateKind :: decode ( decoder) ?
240
+ } ) )
241
241
}
242
242
}
243
243
@@ -471,3 +471,28 @@ macro_rules! implement_ty_decoder {
471
471
}
472
472
}
473
473
}
474
+
475
+ macro_rules! impl_binder_encode_decode {
476
+ ( $( $t: ty) ,+ $( , ) ?) => {
477
+ $(
478
+ impl <' tcx, E : TyEncoder <' tcx>> Encodable <E > for ty:: Binder <$t> {
479
+ fn encode( & self , e: & mut E ) -> Result <( ) , E :: Error > {
480
+ self . as_ref( ) . skip_binder( ) . encode( e)
481
+ }
482
+ }
483
+ impl <' tcx, D : TyDecoder <' tcx>> Decodable <D > for ty:: Binder <$t> {
484
+ fn decode( decoder: & mut D ) -> Result <Self , D :: Error > {
485
+ Ok ( ty:: Binder :: bind( Decodable :: decode( decoder) ?) )
486
+ }
487
+ }
488
+ ) *
489
+ }
490
+ }
491
+
492
+ impl_binder_encode_decode ! {
493
+ & ' tcx ty:: List <Ty <' tcx>>,
494
+ ty:: FnSig <' tcx>,
495
+ ty:: ExistentialPredicate <' tcx>,
496
+ ty:: TraitRef <' tcx>,
497
+ Vec <ty:: GeneratorInteriorTypeCause <' tcx>>,
498
+ }
0 commit comments