diff options
Diffstat (limited to 'compiler/rustc_middle/src/ty/adt.rs')
-rw-r--r-- | compiler/rustc_middle/src/ty/adt.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 771ce2eb884..5cde54c9328 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -11,7 +11,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_index::vec::{Idx, IndexVec}; use rustc_query_system::ich::StableHashingContext; -use rustc_serialize::{self, Encodable, Encoder}; use rustc_session::DataTypeKind; use rustc_span::symbol::sym; use rustc_target::abi::VariantIdx; @@ -20,7 +19,7 @@ use std::cell::RefCell; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; use std::ops::Range; -use std::{ptr, str}; +use std::str; use super::{ Destructor, FieldDef, GenericPredicates, ReprOptions, Ty, TyCtxt, VariantDef, VariantDiscr, @@ -30,7 +29,7 @@ use super::{ pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]); bitflags! { - #[derive(HashStable)] + #[derive(HashStable, TyEncodable, TyDecodable)] pub struct AdtFlags: u32 { const NO_ADT_FLAGS = 0; /// Indicates whether the ADT is an enum. @@ -88,6 +87,7 @@ bitflags! { /// /// where `x` here represents the `DefId` of `S.x`. Then, the `DefId` /// can be used with [`TyCtxt::type_of()`] to get the type of the field. +#[derive(TyEncodable, TyDecodable)] pub struct AdtDef { /// The `DefId` of the struct, enum or union item. pub did: DefId, @@ -113,26 +113,23 @@ impl Ord for AdtDef { } } +/// There should be only one AdtDef for each `did`, therefore +/// it is fine to implement `PartialEq` only based on `did`. impl PartialEq for AdtDef { - // `AdtDef`s are always interned, and this is part of `TyS` equality. #[inline] fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) + self.did == other.did } } impl Eq for AdtDef {} +/// There should be only one AdtDef for each `did`, therefore +/// it is fine to implement `Hash` only based on `did`. impl Hash for AdtDef { #[inline] fn hash<H: Hasher>(&self, s: &mut H) { - (self as *const AdtDef).hash(s) - } -} - -impl<S: Encoder> Encodable<S> for AdtDef { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { - self.did.encode(s) + self.did.hash(s) } } @@ -161,7 +158,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDef { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, TyEncodable, TyDecodable)] pub enum AdtKind { Struct, Union, |