about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-11-16 11:52:00 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-11-17 22:37:16 +0100
commit5b4dad7ad2666237a45e0467374fd744dd01bb6e (patch)
tree5c6259d186b2beb730a9c2b33a665656e579206a /src
parente8e7ad6fb86dc07cb4466a170a38b97d38746902 (diff)
downloadrust-5b4dad7ad2666237a45e0467374fd744dd01bb6e.tar.gz
rust-5b4dad7ad2666237a45e0467374fd744dd01bb6e.zip
Derive HashStable_Generic for ABI types.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_target/abi/mod.rs60
1 files changed, 8 insertions, 52 deletions
diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs
index ff13218831c..ac781819cc3 100644
--- a/src/librustc_target/abi/mod.rs
+++ b/src/librustc_target/abi/mod.rs
@@ -6,7 +6,6 @@ use crate::spec::Target;
 use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
 
 use rustc_index::vec::{Idx, IndexVec};
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_macros::HashStable_Generic;
 use syntax_pos::Span;
 
@@ -244,16 +243,11 @@ pub enum Endian {
 
 /// Size of a type in bytes.
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
+#[derive(HashStable_Generic)]
 pub struct Size {
     raw: u64
 }
 
-impl<CTX> HashStable<CTX> for Size {
-    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
-        self.bytes().hash_stable(hcx, hasher);
-    }
-}
-
 impl Size {
     pub const ZERO: Size = Self::from_bytes(0);
 
@@ -373,16 +367,11 @@ impl AddAssign for Size {
 
 /// Alignment of a type in bytes (always a power of two).
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
+#[derive(HashStable_Generic)]
 pub struct Align {
     pow2: u8,
 }
 
-impl<CTX> HashStable<CTX> for Align {
-    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
-        self.bytes().hash_stable(hcx, hasher);
-    }
-}
-
 impl Align {
     pub fn from_bits(bits: u64) -> Result<Align, String> {
         Align::from_bytes(Size::from_bits(bits).bytes())
@@ -436,8 +425,8 @@ impl Align {
 }
 
 /// A pair of aligments, ABI-mandated and preferred.
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug,
-         RustcEncodable, RustcDecodable, HashStable_Generic)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
+#[derive(HashStable_Generic)]
 pub struct AbiAndPrefAlign {
     pub abi: Align,
     pub pref: Align,
@@ -603,6 +592,7 @@ impl Primitive {
 
 /// Information about one scalar component of a Rust type.
 #[derive(Clone, PartialEq, Eq, Hash, Debug)]
+#[derive(HashStable_Generic)]
 pub struct Scalar {
     pub value: Primitive,
 
@@ -623,15 +613,6 @@ pub struct Scalar {
     pub valid_range: RangeInclusive<u128>,
 }
 
-impl<CTX> HashStable<CTX> for Scalar {
-    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
-        let Scalar { value, ref valid_range } = *self;
-        value.hash_stable(hcx, hasher);
-        valid_range.start().hash_stable(hcx, hasher);
-        valid_range.end().hash_stable(hcx, hasher);
-    }
-}
-
 impl Scalar {
     pub fn is_bool(&self) -> bool {
         if let Int(I8, _) = self.value {
@@ -824,12 +805,8 @@ impl Abi {
 }
 
 rustc_index::newtype_index! {
-    pub struct VariantIdx { .. }
-}
-
-impl<CTX> HashStable<CTX> for VariantIdx {
-    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
-        self.as_u32().hash_stable(hcx, hasher)
+    pub struct VariantIdx {
+        derive [HashStable_Generic]
     }
 }
 
@@ -851,7 +828,7 @@ pub enum Variants {
     },
 }
 
-#[derive(PartialEq, Eq, Hash, Debug)]
+#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
 pub enum DiscriminantKind {
     /// Integer tag holding the discriminant value itself.
     Tag,
@@ -872,27 +849,6 @@ pub enum DiscriminantKind {
     },
 }
 
-impl<CTX> HashStable<CTX> for DiscriminantKind {
-    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
-        use DiscriminantKind::*;
-        std::mem::discriminant(self).hash_stable(hcx, hasher);
-
-        match *self {
-            Tag => {}
-            Niche {
-                dataful_variant,
-                ref niche_variants,
-                niche_start,
-            } => {
-                dataful_variant.hash_stable(hcx, hasher);
-                niche_variants.start().hash_stable(hcx, hasher);
-                niche_variants.end().hash_stable(hcx, hasher);
-                niche_start.hash_stable(hcx, hasher);
-            }
-        }
-    }
-}
-
 #[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
 pub struct Niche {
     pub offset: Size,