Don't derive TyEncodable/TyDecodable for Binder
This commit is contained in:
parent
674735b109
commit
c76f47832a
3 changed files with 35 additions and 10 deletions
|
@ -120,9 +120,9 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::PredicateKind<'tcx> {
|
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Binder<ty::PredicateKind<'tcx>> {
|
||||||
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
encode_with_shorthand(e, self, TyEncoder::predicate_shorthands)
|
encode_with_shorthand(e, &self.skip_binder(), TyEncoder::predicate_shorthands)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,18 +226,18 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::PredicateKind<'tcx> {
|
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Binder<ty::PredicateKind<'tcx>> {
|
||||||
fn decode(decoder: &mut D) -> Result<ty::PredicateKind<'tcx>, D::Error> {
|
fn decode(decoder: &mut D) -> Result<ty::Binder<ty::PredicateKind<'tcx>>, D::Error> {
|
||||||
// Handle shorthands first, if we have an usize > 0x80.
|
// Handle shorthands first, if we have an usize > 0x80.
|
||||||
if decoder.positioned_at_shorthand() {
|
Ok(ty::Binder::bind(if decoder.positioned_at_shorthand() {
|
||||||
let pos = decoder.read_usize()?;
|
let pos = decoder.read_usize()?;
|
||||||
assert!(pos >= SHORTHAND_OFFSET);
|
assert!(pos >= SHORTHAND_OFFSET);
|
||||||
let shorthand = pos - SHORTHAND_OFFSET;
|
let shorthand = pos - SHORTHAND_OFFSET;
|
||||||
|
|
||||||
decoder.with_position(shorthand, ty::PredicateKind::decode)
|
decoder.with_position(shorthand, ty::PredicateKind::decode)?
|
||||||
} else {
|
} else {
|
||||||
Ok(ty::PredicateKind::decode(decoder)?)
|
ty::PredicateKind::decode(decoder)?
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,3 +471,28 @@ macro_rules! implement_ty_decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_binder_encode_decode {
|
||||||
|
($($t:ty),+ $(,)?) => {
|
||||||
|
$(
|
||||||
|
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Binder<$t> {
|
||||||
|
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
|
self.as_ref().skip_binder().encode(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Binder<$t> {
|
||||||
|
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
|
||||||
|
Ok(ty::Binder::bind(Decodable::decode(decoder)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_binder_encode_decode! {
|
||||||
|
&'tcx ty::List<Ty<'tcx>>,
|
||||||
|
ty::FnSig<'tcx>,
|
||||||
|
ty::ExistentialPredicate<'tcx>,
|
||||||
|
ty::TraitRef<'tcx>,
|
||||||
|
Vec<ty::GeneratorInteriorTypeCause<'tcx>>,
|
||||||
|
}
|
||||||
|
|
|
@ -1081,7 +1081,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||||
#[derive(HashStable, TypeFoldable)]
|
#[derive(HashStable, TypeFoldable)]
|
||||||
pub enum PredicateKind<'tcx> {
|
pub enum PredicateKind<'tcx> {
|
||||||
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
|
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
|
||||||
|
|
|
@ -955,7 +955,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
|
||||||
/// erase, or otherwise "discharge" these bound vars, we change the
|
/// erase, or otherwise "discharge" these bound vars, we change the
|
||||||
/// type from `Binder<T>` to just `T` (see
|
/// type from `Binder<T>` to just `T` (see
|
||||||
/// e.g., `liberate_late_bound_regions`).
|
/// e.g., `liberate_late_bound_regions`).
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
pub struct Binder<T>(T);
|
pub struct Binder<T>(T);
|
||||||
|
|
||||||
impl<T> Binder<T> {
|
impl<T> Binder<T> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue