Skip to content

Commit 79c9474

Browse files
authored
Rollup merge of rust-lang#99900 - lcnr:hash-stable-fun, r=cjgillot
remove some manual hash stable impls
2 parents cfd231a + d3ad264 commit 79c9474

File tree

5 files changed

+15
-89
lines changed

5 files changed

+15
-89
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_index::bit_set;
33
use rustc_index::vec;
44
use smallvec::SmallVec;
55
use std::hash::{BuildHasher, Hash, Hasher};
6+
use std::marker::PhantomData;
67
use std::mem;
78

89
#[cfg(test)]
@@ -261,6 +262,10 @@ impl<CTX> HashStable<CTX> for ! {
261262
}
262263
}
263264

265+
impl<CTX, T> HashStable<CTX> for PhantomData<T> {
266+
fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {}
267+
}
268+
264269
impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 {
265270
#[inline]
266271
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {

compiler/rustc_middle/src/traits/query.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ use crate::infer::canonical::{Canonical, QueryResponse};
99
use crate::ty::error::TypeError;
1010
use crate::ty::subst::GenericArg;
1111
use crate::ty::{self, Ty, TyCtxt};
12-
13-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1412
use rustc_errors::struct_span_err;
15-
use rustc_query_system::ich::StableHashingContext;
1613
use rustc_span::source_map::Span;
1714
use std::iter::FromIterator;
18-
use std::mem;
1915

2016
pub mod type_op {
2117
use crate::ty::fold::TypeFoldable;
@@ -226,29 +222,9 @@ pub struct NormalizationResult<'tcx> {
226222
/// case they are called implied bounds). They are fed to the
227223
/// `OutlivesEnv` which in turn is supplied to the region checker and
228224
/// other parts of the inference system.
229-
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
225+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift, HashStable)]
230226
pub enum OutlivesBound<'tcx> {
231227
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
232228
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
233229
RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>),
234230
}
235-
236-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OutlivesBound<'tcx> {
237-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
238-
mem::discriminant(self).hash_stable(hcx, hasher);
239-
match *self {
240-
OutlivesBound::RegionSubRegion(ref a, ref b) => {
241-
a.hash_stable(hcx, hasher);
242-
b.hash_stable(hcx, hasher);
243-
}
244-
OutlivesBound::RegionSubParam(ref a, ref b) => {
245-
a.hash_stable(hcx, hasher);
246-
b.hash_stable(hcx, hasher);
247-
}
248-
OutlivesBound::RegionSubProjection(ref a, ref b) => {
249-
a.hash_stable(hcx, hasher);
250-
b.hash_stable(hcx, hasher);
251-
}
252-
}
253-
}
254-
}

compiler/rustc_middle/src/ty/impls_ty.rs

-40
Original file line numberDiff line numberDiff line change
@@ -101,46 +101,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArgKin
101101
}
102102
}
103103

104-
impl<'a> HashStable<StableHashingContext<'a>> for ty::EarlyBoundRegion {
105-
#[inline]
106-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
107-
self.def_id.hash_stable(hcx, hasher);
108-
self.index.hash_stable(hcx, hasher);
109-
self.name.hash_stable(hcx, hasher);
110-
}
111-
}
112-
113-
impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
114-
#[inline]
115-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
116-
self.index().hash_stable(hcx, hasher);
117-
}
118-
}
119-
120-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::ConstVid<'tcx> {
121-
#[inline]
122-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
123-
self.index.hash_stable(hcx, hasher);
124-
}
125-
}
126-
127-
impl<'tcx> HashStable<StableHashingContext<'tcx>> for ty::BoundVar {
128-
#[inline]
129-
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
130-
self.index().hash_stable(hcx, hasher);
131-
}
132-
}
133-
134-
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for ty::Binder<'tcx, T>
135-
where
136-
T: HashStable<StableHashingContext<'a>>,
137-
{
138-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
139-
self.as_ref().skip_binder().hash_stable(hcx, hasher);
140-
self.bound_vars().hash_stable(hcx, hasher);
141-
}
142-
}
143-
144104
// AllocIds get resolved to whatever they point to (to be stable)
145105
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
146106
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

compiler/rustc_middle/src/ty/mod.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1182,22 +1182,13 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
11821182
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
11831183
/// regions/types/consts within the same universe simply have an unknown relationship to one
11841184
/// another.
1185-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
1185+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1186+
#[derive(HashStable, TyEncodable, TyDecodable)]
11861187
pub struct Placeholder<T> {
11871188
pub universe: UniverseIndex,
11881189
pub name: T,
11891190
}
11901191

1191-
impl<'a, T> HashStable<StableHashingContext<'a>> for Placeholder<T>
1192-
where
1193-
T: HashStable<StableHashingContext<'a>>,
1194-
{
1195-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
1196-
self.universe.hash_stable(hcx, hasher);
1197-
self.name.hash_stable(hcx, hasher);
1198-
}
1199-
}
1200-
12011192
pub type PlaceholderRegion = Placeholder<BoundRegionKind>;
12021193

12031194
pub type PlaceholderType = Placeholder<BoundVar>;
@@ -1581,6 +1572,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
15811572
}
15821573

15831574
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
1575+
#[derive(HashStable)]
15841576
pub struct ParamEnvAnd<'tcx, T> {
15851577
pub param_env: ParamEnv<'tcx>,
15861578
pub value: T,
@@ -1598,18 +1590,6 @@ impl<'tcx, T> ParamEnvAnd<'tcx, T> {
15981590
}
15991591
}
16001592

1601-
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for ParamEnvAnd<'tcx, T>
1602-
where
1603-
T: HashStable<StableHashingContext<'a>>,
1604-
{
1605-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
1606-
let ParamEnvAnd { ref param_env, ref value } = *self;
1607-
1608-
param_env.hash_stable(hcx, hasher);
1609-
value.hash_stable(hcx, hasher);
1610-
}
1611-
}
1612-
16131593
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
16141594
pub struct Destructor {
16151595
/// The `DefId` of the destructor method

compiler/rustc_middle/src/ty/sty.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ impl BoundVariableKind {
10091009
///
10101010
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
10111011
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1012+
#[derive(HashStable)]
10121013
pub struct Binder<'tcx, T>(T, &'tcx List<BoundVariableKind>);
10131014

10141015
impl<'tcx, T> Binder<'tcx, T>
@@ -1355,6 +1356,7 @@ impl<'tcx> fmt::Debug for Region<'tcx> {
13551356
}
13561357

13571358
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
1359+
#[derive(HashStable)]
13581360
pub struct EarlyBoundRegion {
13591361
pub def_id: DefId,
13601362
pub index: u32,
@@ -1368,14 +1370,16 @@ impl fmt::Debug for EarlyBoundRegion {
13681370
}
13691371

13701372
/// A **`const`** **v**ariable **ID**.
1371-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
1373+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1374+
#[derive(HashStable, TyEncodable, TyDecodable)]
13721375
pub struct ConstVid<'tcx> {
13731376
pub index: u32,
13741377
pub phantom: PhantomData<&'tcx ()>,
13751378
}
13761379

13771380
rustc_index::newtype_index! {
13781381
/// A **region** (lifetime) **v**ariable **ID**.
1382+
#[derive(HashStable)]
13791383
pub struct RegionVid {
13801384
DEBUG_FORMAT = custom,
13811385
}
@@ -1388,6 +1392,7 @@ impl Atom for RegionVid {
13881392
}
13891393

13901394
rustc_index::newtype_index! {
1395+
#[derive(HashStable)]
13911396
pub struct BoundVar { .. }
13921397
}
13931398

0 commit comments

Comments
 (0)