diff --git a/Cargo.lock b/Cargo.lock index a9090201710a4..ec7d0b68a334c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1014,8 +1014,7 @@ dependencies = [ [[package]] name = "derivative" version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +source = "git+https://github.com/compiler-errors/rust-derivative.git?branch=eq#d1f5d08ebcec06f0acea2957efba632b7ddf8666" dependencies = [ "proc-macro2", "quote", diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index b39ba305913e3..04986c7da51e3 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start bitflags = "1.2.1" -derivative = "2.2.0" +derivative = { git = "https://github.com/compiler-errors/rust-derivative.git", branch = "eq" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index c8e730b585ad9..ef4ceed81cf90 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -14,7 +14,12 @@ 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"), Hash(bound = "V: Hash"))] +#[derivative( + Clone(bound = "V: Clone"), + Hash(bound = "V: Hash"), + PartialEq(bound = "V: PartialEq"), + Eq(bound = "V: Eq") +)] pub struct Canonical { pub value: V, pub max_universe: UniverseIndex, @@ -72,16 +77,6 @@ where } } -impl Eq for Canonical {} - -impl PartialEq for Canonical { - fn eq(&self, other: &Self) -> bool { - self.value == other.value - && self.max_universe == other.max_universe - && self.variables == other.variables - } -} - impl fmt::Display for Canonical { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index cf67ba0b21a1a..960e599eec771 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -18,7 +18,9 @@ use self::ConstKind::*; PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), Ord = "feature_allow_slow_enum", - Hash(bound = "") + Hash(bound = ""), + PartialEq(skip_discriminant = "true", bound = ""), + Eq(bound = "") )] pub enum ConstKind { /// A const generic parameter. @@ -153,24 +155,6 @@ where } } -impl PartialEq for ConstKind { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Param(l0), Param(r0)) => l0 == r0, - (Infer(l0), Infer(r0)) => l0 == r0, - (Bound(l0, l1), Bound(r0, r1)) => l0 == r0 && l1 == r1, - (Placeholder(l0), Placeholder(r0)) => l0 == r0, - (Unevaluated(l0), Unevaluated(r0)) => l0 == r0, - (Value(l0), Value(r0)) => l0 == r0, - (Error(l0), Error(r0)) => l0 == r0, - (Expr(l0), Expr(r0)) => l0 == r0, - _ => false, - } - } -} - -impl Eq for ConstKind {} - impl fmt::Debug for ConstKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { WithInfcx::with_no_infcx(self).fmt(f) diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index 23117fdd53109..a4227a09699cb 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -12,7 +12,12 @@ 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 = ""), Hash(bound = ""))] +#[derivative( + Clone(bound = ""), + Hash(bound = ""), + PartialEq(skip_discriminant = "true", bound = ""), + Eq(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` @@ -52,23 +57,6 @@ where { } -impl PartialEq for ClauseKind { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Trait(l0), Self::Trait(r0)) => l0 == r0, - (Self::RegionOutlives(l0), Self::RegionOutlives(r0)) => l0 == r0, - (Self::TypeOutlives(l0), Self::TypeOutlives(r0)) => l0 == r0, - (Self::Projection(l0), Self::Projection(r0)) => l0 == r0, - (Self::ConstArgHasType(l0, l1), Self::ConstArgHasType(r0, r1)) => l0 == r0 && l1 == r1, - (Self::WellFormed(l0), Self::WellFormed(r0)) => l0 == r0, - (Self::ConstEvaluatable(l0), Self::ConstEvaluatable(r0)) => l0 == r0, - _ => false, - } - } -} - -impl Eq for ClauseKind {} - fn clause_kind_discriminant(value: &ClauseKind) -> usize { match value { ClauseKind::Trait(_) => 0, @@ -219,7 +207,12 @@ where } #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""), Hash(bound = ""))] +#[derivative( + Clone(bound = ""), + Hash(bound = ""), + PartialEq(skip_discriminant = "true", bound = ""), + Eq(bound = "") +)] pub enum PredicateKind { /// Prove a clause Clause(ClauseKind), @@ -276,27 +269,6 @@ where { } -impl PartialEq for PredicateKind { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Clause(l0), Self::Clause(r0)) => l0 == r0, - (Self::ObjectSafe(l0), Self::ObjectSafe(r0)) => l0 == r0, - (Self::ClosureKind(l0, l1, l2), Self::ClosureKind(r0, r1, r2)) => { - l0 == r0 && l1 == r1 && l2 == r2 - } - (Self::Subtype(l0), Self::Subtype(r0)) => l0 == r0, - (Self::Coerce(l0), Self::Coerce(r0)) => l0 == r0, - (Self::ConstEquate(l0, l1), Self::ConstEquate(r0, r1)) => l0 == r0 && l1 == r1, - (Self::AliasRelate(l0, l1, l2), Self::AliasRelate(r0, r1, r2)) => { - l0 == r0 && l1 == r1 && l2 == r2 - } - _ => core::mem::discriminant(self) == core::mem::discriminant(other), - } - } -} - -impl Eq for PredicateKind {} - fn predicate_kind_discriminant(value: &PredicateKind) -> usize { match value { PredicateKind::Clause(_) => 0, diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 72f86fc069299..d5241eb68a881 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -123,7 +123,9 @@ use self::RegionKind::*; PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), Ord = "feature_allow_slow_enum", - Hash(bound = "") + Hash(bound = ""), + PartialEq(bound = ""), + Eq(bound = "") )] pub enum RegionKind { /// Region bound in a type or fn declaration which will be @@ -185,34 +187,6 @@ where { } -// This is manually implemented because a derive would require `I: PartialEq` -impl PartialEq for RegionKind { - #[inline] - fn eq(&self, other: &RegionKind) -> bool { - regionkind_discriminant(self) == regionkind_discriminant(other) - && match (self, other) { - (ReEarlyBound(a_r), ReEarlyBound(b_r)) => a_r == b_r, - (ReLateBound(a_d, a_r), ReLateBound(b_d, b_r)) => a_d == b_d && a_r == b_r, - (ReFree(a_r), ReFree(b_r)) => a_r == b_r, - (ReStatic, ReStatic) => true, - (ReVar(a_r), ReVar(b_r)) => a_r == b_r, - (RePlaceholder(a_r), RePlaceholder(b_r)) => a_r == b_r, - (ReErased, ReErased) => true, - (ReError(_), ReError(_)) => true, - _ => { - debug_assert!( - false, - "This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}" - ); - true - } - } - } -} - -// This is manually implemented because a derive would require `I: Eq` -impl Eq for RegionKind {} - 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 dceb5ba0560b1..a8f1339ab6c82 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -120,7 +120,9 @@ pub enum AliasKind { PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), Ord = "feature_allow_slow_enum", - Hash(bound = "") + Hash(bound = ""), + PartialEq(skip_discriminant = "true", bound = ""), + Eq(bound = "") )] pub enum TyKind { /// The primitive boolean type. Written as `bool`. @@ -332,58 +334,6 @@ const fn tykind_discriminant(value: &TyKind) -> usize { } } -// This is manually implemented because a derive would require `I: PartialEq` -impl PartialEq for TyKind { - #[inline] - fn eq(&self, other: &TyKind) -> bool { - // You might expect this `match` to be preceded with this: - // - // tykind_discriminant(self) == tykind_discriminant(other) && - // - // but the data patterns in practice are such that a comparison - // succeeds 99%+ of the time, and it's faster to omit it. - match (self, other) { - (Int(a_i), Int(b_i)) => a_i == b_i, - (Uint(a_u), Uint(b_u)) => a_u == b_u, - (Float(a_f), Float(b_f)) => a_f == b_f, - (Adt(a_d, a_s), Adt(b_d, b_s)) => a_d == b_d && a_s == b_s, - (Foreign(a_d), Foreign(b_d)) => a_d == b_d, - (Array(a_t, a_c), Array(b_t, b_c)) => a_t == b_t && a_c == b_c, - (Slice(a_t), Slice(b_t)) => a_t == b_t, - (RawPtr(a_t), RawPtr(b_t)) => a_t == b_t, - (Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => a_r == b_r && a_t == b_t && a_m == b_m, - (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d == b_d && a_s == b_s, - (FnPtr(a_s), FnPtr(b_s)) => a_s == b_s, - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { - a_p == b_p && a_r == b_r && a_repr == b_repr - } - (Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s, - (Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { - a_d == b_d && a_s == b_s && a_m == b_m - } - (CoroutineWitness(a_d, a_s), CoroutineWitness(b_d, b_s)) => a_d == b_d && a_s == b_s, - (Tuple(a_t), Tuple(b_t)) => a_t == b_t, - (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, - (Param(a_p), Param(b_p)) => a_p == b_p, - (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, - (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, - (Infer(a_t), Infer(b_t)) => a_t == b_t, - (Error(a_e), Error(b_e)) => a_e == b_e, - (Bool, Bool) | (Char, Char) | (Str, Str) | (Never, Never) => true, - _ => { - debug_assert!( - tykind_discriminant(self) != tykind_discriminant(other), - "This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}" - ); - false - } - } - } -} - -// This is manually implemented because a derive would require `I: Eq` -impl Eq for TyKind {} - impl DebugWithInfcx for TyKind { fn fmt>( this: WithInfcx<'_, Infcx, &Self>, diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index aad57cacbb41e..77e82447a92e9 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -4,7 +4,10 @@ use std::fs; use std::path::Path; /// List of allowed sources for packages. -const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""]; +const ALLOWED_SOURCES: &[&str] = &[ + "\"registry+https://github.com/rust-lang/crates.io-index\"", + "\"git+https://github.com/compiler-errors/rust-derivative.git?branch=eq#d1f5d08ebcec06f0acea2957efba632b7ddf8666\"", +]; /// Checks for external package sources. `root` is the path to the directory that contains the /// workspace `Cargo.toml`.