From d3ad264a91d9efba20c59753d88bc350f99dd952 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 29 Jul 2022 12:48:28 +0200 Subject: [PATCH] remove some manual hash stable impls --- .../src/stable_hasher.rs | 5 +++ compiler/rustc_middle/src/traits/query.rs | 26 +----------- compiler/rustc_middle/src/ty/impls_ty.rs | 40 ------------------- compiler/rustc_middle/src/ty/mod.rs | 26 ++---------- compiler/rustc_middle/src/ty/sty.rs | 7 +++- 5 files changed, 15 insertions(+), 89 deletions(-) diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index a915a4daa9541..ce85917341880 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -3,6 +3,7 @@ use rustc_index::bit_set; use rustc_index::vec; use smallvec::SmallVec; use std::hash::{BuildHasher, Hash, Hasher}; +use std::marker::PhantomData; use std::mem; #[cfg(test)] @@ -261,6 +262,10 @@ impl HashStable for ! { } } +impl HashStable for PhantomData { + fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {} +} + impl HashStable for ::std::num::NonZeroU32 { #[inline] fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index 937b166d484b3..1f9b474ade12b 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -9,13 +9,9 @@ use crate::infer::canonical::{Canonical, QueryResponse}; use crate::ty::error::TypeError; use crate::ty::subst::GenericArg; use crate::ty::{self, Ty, TyCtxt}; - -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::struct_span_err; -use rustc_query_system::ich::StableHashingContext; use rustc_span::source_map::Span; use std::iter::FromIterator; -use std::mem; pub mod type_op { use crate::ty::fold::TypeFoldable; @@ -226,29 +222,9 @@ pub struct NormalizationResult<'tcx> { /// case they are called implied bounds). They are fed to the /// `OutlivesEnv` which in turn is supplied to the region checker and /// other parts of the inference system. -#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift)] +#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift, HashStable)] pub enum OutlivesBound<'tcx> { RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>), RegionSubParam(ty::Region<'tcx>, ty::ParamTy), RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>), } - -impl<'a, 'tcx> HashStable> for OutlivesBound<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - OutlivesBound::RegionSubRegion(ref a, ref b) => { - a.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - OutlivesBound::RegionSubParam(ref a, ref b) => { - a.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - OutlivesBound::RegionSubProjection(ref a, ref b) => { - a.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - } - } -} diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index 263d64a57776a..cd00b26b8def0 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -101,46 +101,6 @@ impl<'a, 'tcx> HashStable> for ty::subst::GenericArgKin } } -impl<'a> HashStable> for ty::EarlyBoundRegion { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.def_id.hash_stable(hcx, hasher); - self.index.hash_stable(hcx, hasher); - self.name.hash_stable(hcx, hasher); - } -} - -impl<'a> HashStable> for ty::RegionVid { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a, 'tcx> HashStable> for ty::ConstVid<'tcx> { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.index.hash_stable(hcx, hasher); - } -} - -impl<'tcx> HashStable> for ty::BoundVar { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a, 'tcx, T> HashStable> for ty::Binder<'tcx, T> -where - T: HashStable>, -{ - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.as_ref().skip_binder().hash_stable(hcx, hasher); - self.bound_vars().hash_stable(hcx, hasher); - } -} - // AllocIds get resolved to whatever they point to (to be stable) impl<'a> HashStable> for mir::interpret::AllocId { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 31c523aaca9ae..da9d51a29b18c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1182,22 +1182,13 @@ impl<'tcx> OpaqueHiddenType<'tcx> { /// identified by both a universe, as well as a name residing within that universe. Distinct bound /// regions/types/consts within the same universe simply have an unknown relationship to one /// another. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(HashStable, TyEncodable, TyDecodable)] pub struct Placeholder { pub universe: UniverseIndex, pub name: T, } -impl<'a, T> HashStable> for Placeholder -where - T: HashStable>, -{ - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.universe.hash_stable(hcx, hasher); - self.name.hash_stable(hcx, hasher); - } -} - pub type PlaceholderRegion = Placeholder; pub type PlaceholderType = Placeholder; @@ -1581,6 +1572,7 @@ impl<'tcx> PolyTraitRef<'tcx> { } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] +#[derive(HashStable)] pub struct ParamEnvAnd<'tcx, T> { pub param_env: ParamEnv<'tcx>, pub value: T, @@ -1598,18 +1590,6 @@ impl<'tcx, T> ParamEnvAnd<'tcx, T> { } } -impl<'a, 'tcx, T> HashStable> for ParamEnvAnd<'tcx, T> -where - T: HashStable>, -{ - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let ParamEnvAnd { ref param_env, ref value } = *self; - - param_env.hash_stable(hcx, hasher); - value.hash_stable(hcx, hasher); - } -} - #[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] pub struct Destructor { /// The `DefId` of the destructor method diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9f622ad6cd2a1..e961e3bf15545 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -986,6 +986,7 @@ pub enum BoundVariableKind { /// /// `Decodable` and `Encodable` are implemented for `Binder` using the `impl_binder_encode_decode!` macro. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(HashStable)] pub struct Binder<'tcx, T>(T, &'tcx List); impl<'tcx, T> Binder<'tcx, T> @@ -1332,6 +1333,7 @@ impl<'tcx> fmt::Debug for Region<'tcx> { } #[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(HashStable)] pub struct EarlyBoundRegion { pub def_id: DefId, pub index: u32, @@ -1345,7 +1347,8 @@ impl fmt::Debug for EarlyBoundRegion { } /// A **`const`** **v**ariable **ID**. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(HashStable, TyEncodable, TyDecodable)] pub struct ConstVid<'tcx> { pub index: u32, pub phantom: PhantomData<&'tcx ()>, @@ -1353,6 +1356,7 @@ pub struct ConstVid<'tcx> { rustc_index::newtype_index! { /// A **region** (lifetime) **v**ariable **ID**. + #[derive(HashStable)] pub struct RegionVid { DEBUG_FORMAT = custom, } @@ -1365,6 +1369,7 @@ impl Atom for RegionVid { } rustc_index::newtype_index! { + #[derive(HashStable)] pub struct BoundVar { .. } }