Skip to content

Commit c76f478

Browse files
committedJan 17, 2021
Don't derive TyEncodable/TyDecodable for Binder
1 parent 674735b commit c76f478

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed
 

‎compiler/rustc_middle/src/ty/codec.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
120120
}
121121
}
122122

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>> {
124124
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)
126126
}
127127
}
128128

@@ -226,18 +226,18 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
226226
}
227227
}
228228

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> {
231231
// 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() {
233233
let pos = decoder.read_usize()?;
234234
assert!(pos >= SHORTHAND_OFFSET);
235235
let shorthand = pos - SHORTHAND_OFFSET;
236236

237-
decoder.with_position(shorthand, ty::PredicateKind::decode)
237+
decoder.with_position(shorthand, ty::PredicateKind::decode)?
238238
} else {
239-
Ok(ty::PredicateKind::decode(decoder)?)
240-
}
239+
ty::PredicateKind::decode(decoder)?
240+
}))
241241
}
242242
}
243243

@@ -471,3 +471,28 @@ macro_rules! implement_ty_decoder {
471471
}
472472
}
473473
}
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+
}

‎compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
10811081
}
10821082
}
10831083

1084-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1084+
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
10851085
#[derive(HashStable, TypeFoldable)]
10861086
pub enum PredicateKind<'tcx> {
10871087
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be

‎compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
955955
/// erase, or otherwise "discharge" these bound vars, we change the
956956
/// type from `Binder<T>` to just `T` (see
957957
/// e.g., `liberate_late_bound_regions`).
958-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
958+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
959959
pub struct Binder<T>(T);
960960

961961
impl<T> Binder<T> {

0 commit comments

Comments
 (0)
Please sign in to comment.