diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 1333a29a141cd..c8e730b585ad9 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::hash; +use std::hash::Hash; use std::ops::ControlFlow; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -14,7 +14,7 @@ use crate::{HashStableContext, Interner, TyEncoder, UniverseIndex}; /// variables have been rewritten to "canonical vars". These are /// numbered starting from 0 in order of first appearance. #[derive(derivative::Derivative)] -#[derivative(Clone(bound = "V: Clone"))] +#[derivative(Clone(bound = "V: Clone"), Hash(bound = "V: Hash"))] pub struct Canonical { pub value: V, pub max_universe: UniverseIndex, @@ -61,14 +61,6 @@ impl Canonical { } } -impl hash::Hash for Canonical { - fn hash(&self, state: &mut H) { - self.value.hash(state); - self.max_universe.hash(state); - self.variables.hash(state); - } -} - impl> HashStable for Canonical where I::CanonicalVars: HashStable, diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 3c986f64d38d7..cf67ba0b21a1a 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -2,7 +2,6 @@ use rustc_data_structures::stable_hasher::HashStable; use rustc_data_structures::stable_hasher::StableHasher; use rustc_serialize::{Decodable, Decoder, Encodable}; use std::fmt; -use std::hash; use crate::{ DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, TyDecoder, @@ -18,7 +17,8 @@ use self::ConstKind::*; PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), - Ord = "feature_allow_slow_enum" + Ord = "feature_allow_slow_enum", + Hash(bound = "") )] pub enum ConstKind { /// A const generic parameter. @@ -63,25 +63,6 @@ const fn const_kind_discriminant(value: &ConstKind) -> usize { } } -impl hash::Hash for ConstKind { - fn hash(&self, state: &mut H) { - const_kind_discriminant(self).hash(state); - match self { - Param(p) => p.hash(state), - Infer(i) => i.hash(state), - Bound(d, b) => { - d.hash(state); - b.hash(state); - } - Placeholder(p) => p.hash(state), - Unevaluated(u) => u.hash(state), - Value(v) => v.hash(state), - Error(e) => e.hash(state), - Expr(e) => e.hash(state), - } - } -} - impl HashStable for ConstKind where I::ParamConst: HashStable, diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index 124d9d0eb9598..23117fdd53109 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -2,7 +2,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_serialize::Decoder; use rustc_serialize::{Decodable, Encodable}; use std::fmt; -use std::hash; use std::ops::ControlFlow; use crate::fold::{FallibleTypeFolder, TypeFoldable}; @@ -13,7 +12,7 @@ use crate::{TyDecoder, TyEncoder}; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""))] +#[derivative(Clone(bound = ""), Hash(bound = ""))] pub enum ClauseKind { /// Corresponds to `where Foo: Bar`. `Foo` here would be /// the `Self` type of the trait reference and `A`, `B`, and `C` @@ -82,24 +81,6 @@ fn clause_kind_discriminant(value: &ClauseKind) -> usize { } } -impl hash::Hash for ClauseKind { - fn hash(&self, state: &mut H) { - clause_kind_discriminant(self).hash(state); - match self { - ClauseKind::Trait(p) => p.hash(state), - ClauseKind::RegionOutlives(p) => p.hash(state), - ClauseKind::TypeOutlives(p) => p.hash(state), - ClauseKind::Projection(p) => p.hash(state), - ClauseKind::ConstArgHasType(c, t) => { - c.hash(state); - t.hash(state); - } - ClauseKind::WellFormed(t) => t.hash(state), - ClauseKind::ConstEvaluatable(c) => c.hash(state), - } - } -} - impl HashStable for ClauseKind where I::Ty: HashStable, @@ -238,7 +219,7 @@ where } #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""))] +#[derivative(Clone(bound = ""), Hash(bound = ""))] pub enum PredicateKind { /// Prove a clause Clause(ClauseKind), @@ -329,33 +310,6 @@ fn predicate_kind_discriminant(value: &PredicateKind) -> usize { } } -impl hash::Hash for PredicateKind { - fn hash(&self, state: &mut H) { - predicate_kind_discriminant(self).hash(state); - match self { - PredicateKind::Clause(p) => p.hash(state), - PredicateKind::ObjectSafe(d) => d.hash(state), - PredicateKind::ClosureKind(d, g, k) => { - d.hash(state); - g.hash(state); - k.hash(state); - } - PredicateKind::Subtype(p) => p.hash(state), - PredicateKind::Coerce(p) => p.hash(state), - PredicateKind::ConstEquate(c1, c2) => { - c1.hash(state); - c2.hash(state); - } - PredicateKind::Ambiguous => {} - PredicateKind::AliasRelate(t1, t2, r) => { - t1.hash(state); - t2.hash(state); - r.hash(state); - } - } - } -} - impl HashStable for PredicateKind where I::DefId: HashStable, diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 8dc1cc0800584..72f86fc069299 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -2,7 +2,6 @@ use rustc_data_structures::stable_hasher::HashStable; use rustc_data_structures::stable_hasher::StableHasher; use rustc_serialize::{Decodable, Decoder, Encodable}; use std::fmt; -use std::hash; use crate::{ DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, TyDecoder, @@ -123,7 +122,8 @@ use self::RegionKind::*; PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), - Ord = "feature_allow_slow_enum" + Ord = "feature_allow_slow_enum", + Hash(bound = "") )] pub enum RegionKind { /// Region bound in a type or fn declaration which will be @@ -213,26 +213,6 @@ impl PartialEq for RegionKind { // This is manually implemented because a derive would require `I: Eq` impl Eq for RegionKind {} -// This is manually implemented because a derive would require `I: Hash` -impl hash::Hash for RegionKind { - fn hash(&self, state: &mut H) -> () { - regionkind_discriminant(self).hash(state); - match self { - ReEarlyBound(r) => r.hash(state), - ReLateBound(d, r) => { - d.hash(state); - r.hash(state) - } - ReFree(r) => r.hash(state), - ReStatic => (), - ReVar(r) => r.hash(state), - RePlaceholder(r) => r.hash(state), - ReErased => (), - ReError(_) => (), - } - } -} - impl DebugWithInfcx for RegionKind { fn fmt>( this: WithInfcx<'_, Infcx, &Self>, diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index f180ceb7b0710..dceb5ba0560b1 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -3,8 +3,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::unify::{EqUnifyValue, UnifyKey}; use rustc_serialize::{Decodable, Decoder, Encodable}; +use std::fmt; use std::mem::discriminant; -use std::{fmt, hash}; use crate::HashStableContext; use crate::Interner; @@ -119,7 +119,8 @@ pub enum AliasKind { PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), - Ord = "feature_allow_slow_enum" + Ord = "feature_allow_slow_enum", + Hash(bound = "") )] pub enum TyKind { /// The primitive boolean type. Written as `bool`. @@ -383,71 +384,6 @@ impl PartialEq for TyKind { // This is manually implemented because a derive would require `I: Eq` impl Eq for TyKind {} -// This is manually implemented because a derive would require `I: Hash` -impl hash::Hash for TyKind { - fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () { - tykind_discriminant(self).hash(state); - match self { - Int(i) => i.hash(state), - Uint(u) => u.hash(state), - Float(f) => f.hash(state), - Adt(d, s) => { - d.hash(state); - s.hash(state) - } - Foreign(d) => d.hash(state), - Array(t, c) => { - t.hash(state); - c.hash(state) - } - Slice(t) => t.hash(state), - RawPtr(t) => t.hash(state), - Ref(r, t, m) => { - r.hash(state); - t.hash(state); - m.hash(state) - } - FnDef(d, s) => { - d.hash(state); - s.hash(state) - } - FnPtr(s) => s.hash(state), - Dynamic(p, r, repr) => { - p.hash(state); - r.hash(state); - repr.hash(state) - } - Closure(d, s) => { - d.hash(state); - s.hash(state) - } - Coroutine(d, s, m) => { - d.hash(state); - s.hash(state); - m.hash(state) - } - CoroutineWitness(d, s) => { - d.hash(state); - s.hash(state); - } - Tuple(t) => t.hash(state), - Alias(i, p) => { - i.hash(state); - p.hash(state); - } - Param(p) => p.hash(state), - Bound(d, b) => { - d.hash(state); - b.hash(state) - } - Placeholder(p) => p.hash(state), - Infer(t) => t.hash(state), - Error(e) => e.hash(state), - Bool | Char | Str | Never => (), - } - } -} - impl DebugWithInfcx for TyKind { fn fmt>( this: WithInfcx<'_, Infcx, &Self>,