Skip to content

Commit 5b4dad7

Browse files
committed
Derive HashStable_Generic for ABI types.
1 parent e8e7ad6 commit 5b4dad7

File tree

1 file changed

+8
-52
lines changed

1 file changed

+8
-52
lines changed

src/librustc_target/abi/mod.rs

+8-52
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::spec::Target;
66
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
77

88
use rustc_index::vec::{Idx, IndexVec};
9-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
109
use rustc_macros::HashStable_Generic;
1110
use syntax_pos::Span;
1211

@@ -244,16 +243,11 @@ pub enum Endian {
244243

245244
/// Size of a type in bytes.
246245
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
246+
#[derive(HashStable_Generic)]
247247
pub struct Size {
248248
raw: u64
249249
}
250250

251-
impl<CTX> HashStable<CTX> for Size {
252-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
253-
self.bytes().hash_stable(hcx, hasher);
254-
}
255-
}
256-
257251
impl Size {
258252
pub const ZERO: Size = Self::from_bytes(0);
259253

@@ -373,16 +367,11 @@ impl AddAssign for Size {
373367

374368
/// Alignment of a type in bytes (always a power of two).
375369
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
370+
#[derive(HashStable_Generic)]
376371
pub struct Align {
377372
pow2: u8,
378373
}
379374

380-
impl<CTX> HashStable<CTX> for Align {
381-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
382-
self.bytes().hash_stable(hcx, hasher);
383-
}
384-
}
385-
386375
impl Align {
387376
pub fn from_bits(bits: u64) -> Result<Align, String> {
388377
Align::from_bytes(Size::from_bits(bits).bytes())
@@ -436,8 +425,8 @@ impl Align {
436425
}
437426

438427
/// A pair of aligments, ABI-mandated and preferred.
439-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug,
440-
RustcEncodable, RustcDecodable, HashStable_Generic)]
428+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
429+
#[derive(HashStable_Generic)]
441430
pub struct AbiAndPrefAlign {
442431
pub abi: Align,
443432
pub pref: Align,
@@ -603,6 +592,7 @@ impl Primitive {
603592

604593
/// Information about one scalar component of a Rust type.
605594
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
595+
#[derive(HashStable_Generic)]
606596
pub struct Scalar {
607597
pub value: Primitive,
608598

@@ -623,15 +613,6 @@ pub struct Scalar {
623613
pub valid_range: RangeInclusive<u128>,
624614
}
625615

626-
impl<CTX> HashStable<CTX> for Scalar {
627-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
628-
let Scalar { value, ref valid_range } = *self;
629-
value.hash_stable(hcx, hasher);
630-
valid_range.start().hash_stable(hcx, hasher);
631-
valid_range.end().hash_stable(hcx, hasher);
632-
}
633-
}
634-
635616
impl Scalar {
636617
pub fn is_bool(&self) -> bool {
637618
if let Int(I8, _) = self.value {
@@ -824,12 +805,8 @@ impl Abi {
824805
}
825806

826807
rustc_index::newtype_index! {
827-
pub struct VariantIdx { .. }
828-
}
829-
830-
impl<CTX> HashStable<CTX> for VariantIdx {
831-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
832-
self.as_u32().hash_stable(hcx, hasher)
808+
pub struct VariantIdx {
809+
derive [HashStable_Generic]
833810
}
834811
}
835812

@@ -851,7 +828,7 @@ pub enum Variants {
851828
},
852829
}
853830

854-
#[derive(PartialEq, Eq, Hash, Debug)]
831+
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
855832
pub enum DiscriminantKind {
856833
/// Integer tag holding the discriminant value itself.
857834
Tag,
@@ -872,27 +849,6 @@ pub enum DiscriminantKind {
872849
},
873850
}
874851

875-
impl<CTX> HashStable<CTX> for DiscriminantKind {
876-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
877-
use DiscriminantKind::*;
878-
std::mem::discriminant(self).hash_stable(hcx, hasher);
879-
880-
match *self {
881-
Tag => {}
882-
Niche {
883-
dataful_variant,
884-
ref niche_variants,
885-
niche_start,
886-
} => {
887-
dataful_variant.hash_stable(hcx, hasher);
888-
niche_variants.start().hash_stable(hcx, hasher);
889-
niche_variants.end().hash_stable(hcx, hasher);
890-
niche_start.hash_stable(hcx, hasher);
891-
}
892-
}
893-
}
894-
}
895-
896852
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
897853
pub struct Niche {
898854
pub offset: Size,

0 commit comments

Comments
 (0)