diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index c8521624ebbf9..fc56b006d9429 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -68,7 +68,7 @@ impl From> for DebugSolver { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipGoalEvaluation { pub uncanonicalized_goal: Goal, pub orig_values: Vec, @@ -78,6 +78,8 @@ struct WipGoalEvaluation { pub result: Option>, } +impl Eq for WipGoalEvaluation {} + impl WipGoalEvaluation { fn finalize(self) -> inspect::GoalEvaluation { inspect::GoalEvaluation { @@ -98,7 +100,7 @@ impl WipGoalEvaluation { /// This only exists during proof tree building and does not have /// a corresponding struct in `inspect`. We need this to track a /// bunch of metadata about the current evaluation. -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipCanonicalGoalEvaluationStep { /// Unlike `EvalCtxt::var_values`, we append a new /// generic arg here whenever we create a new inference @@ -111,6 +113,8 @@ struct WipCanonicalGoalEvaluationStep { evaluation: WipProbe, } +impl Eq for WipCanonicalGoalEvaluationStep {} + impl WipCanonicalGoalEvaluationStep { fn current_evaluation_scope(&mut self) -> &mut WipProbe { let mut current = &mut self.evaluation; @@ -132,7 +136,7 @@ impl WipCanonicalGoalEvaluationStep { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipProbe { initial_num_var_values: usize, steps: Vec>, @@ -140,6 +144,8 @@ struct WipProbe { final_state: Option>, } +impl Eq for WipProbe {} + impl WipProbe { fn finalize(self) -> inspect::Probe { inspect::Probe { @@ -150,7 +156,7 @@ impl WipProbe { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] enum WipProbeStep { AddGoal(GoalSource, inspect::CanonicalState>), NestedProbe(WipProbe), @@ -158,6 +164,8 @@ enum WipProbeStep { RecordImplArgs { impl_args: inspect::CanonicalState }, } +impl Eq for WipProbeStep {} + impl WipProbeStep { fn finalize(self) -> inspect::ProbeStep { match self { diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 10d48526fd2a6..6591d3148cb14 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -1,5 +1,3 @@ -use std::fmt::Debug; -use std::hash::Hash; use std::marker::PhantomData; use std::ops::{ControlFlow, Deref}; @@ -23,18 +21,16 @@ use crate::{self as ty, Interner}; /// for more details. /// /// `Decodable` and `Encodable` are implemented for `Binder` using the `impl_binder_encode_decode!` macro. -#[derive_where(Clone; I: Interner, T: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, T)] #[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Debug; I: Interner, T: Debug)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct Binder { value: T, bound_vars: I::BoundVarKinds, } +impl Eq for Binder {} + // FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't // understand how to turn `T` to `T::Lifted` in the output `type Lifted`. impl Lift for Binder @@ -356,14 +352,9 @@ impl TypeVisitor for ValidateBoundVars { /// `instantiate`. /// /// See for more details. -#[derive_where(Clone; I: Interner, T: Clone)] -#[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Ord; I: Interner, T: Ord)] +#[derive_where(Clone, PartialEq, Ord, Hash, Debug; I: Interner, T)] #[derive_where(PartialOrd; I: Interner, T: Ord)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(Debug; I: Interner, T: Debug)] +#[derive_where(Copy; I: Interner, T: Copy)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -374,6 +365,8 @@ pub struct EarlyBinder { _tcx: PhantomData I>, } +impl Eq for EarlyBinder {} + /// For early binders, you should first call `instantiate` before using any visitors. #[cfg(feature = "nightly")] impl !TypeFoldable for ty::EarlyBinder {} diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 0cb8d8902c6ff..de2a9186e7c94 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -11,11 +11,7 @@ use crate::data_structures::HashMap; use crate::inherent::*; use crate::{self as ty, Interner, TypingMode, UniverseIndex}; -#[derive_where(Clone; I: Interner, V: Clone)] -#[derive_where(Hash; I: Interner, V: Hash)] -#[derive_where(PartialEq; I: Interner, V: PartialEq)] -#[derive_where(Eq; I: Interner, V: Eq)] -#[derive_where(Debug; I: Interner, V: fmt::Debug)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] #[cfg_attr( feature = "nightly", @@ -26,14 +22,12 @@ pub struct CanonicalQueryInput { pub typing_mode: TypingMode, } +impl Eq for CanonicalQueryInput {} + /// A "canonicalized" type `V` is one where all free inference /// variables have been rewritten to "canonical vars". These are /// numbered starting from 0 in order of first appearance. -#[derive_where(Clone; I: Interner, V: Clone)] -#[derive_where(Hash; I: Interner, V: Hash)] -#[derive_where(PartialEq; I: Interner, V: PartialEq)] -#[derive_where(Eq; I: Interner, V: Eq)] -#[derive_where(Debug; I: Interner, V: fmt::Debug)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] #[cfg_attr( feature = "nightly", @@ -45,6 +39,8 @@ pub struct Canonical { pub variables: I::CanonicalVarKinds, } +impl Eq for Canonical {} + impl Canonical { /// Allows you to map the `value` of a canonical while keeping the /// same set of bound variables. @@ -89,7 +85,7 @@ impl fmt::Display for Canonical { /// canonical value. This is sufficient information for code to create /// a copy of the canonical value in some other inference context, /// with fresh inference variables replacing the canonical values. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -116,6 +112,8 @@ pub enum CanonicalVarKind { PlaceholderConst(I::PlaceholderConst), } +impl Eq for CanonicalVarKind {} + impl CanonicalVarKind { pub fn universe(self) -> UniverseIndex { match self { @@ -223,7 +221,7 @@ pub enum CanonicalTyVarKind { /// vectors with the original values that were replaced by canonical /// variables. You will need to supply it later to instantiate the /// canonicalized query response. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -233,6 +231,8 @@ pub struct CanonicalVarValues { pub var_values: I::GenericArgs, } +impl Eq for CanonicalVarValues {} + impl CanonicalVarValues { pub fn is_identity(&self) -> bool { self.var_values.iter().enumerate().all(|(bv, arg)| match arg.kind() { diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 70a8509b51339..6de41b47bde08 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -10,7 +10,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen use crate::{self as ty, DebruijnIndex, Interner}; /// Represents a constant in Rust. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -45,6 +45,8 @@ pub enum ConstKind { Expr(I::ExprConst), } +impl Eq for ConstKind {} + impl fmt::Debug for ConstKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ConstKind::*; @@ -63,7 +65,7 @@ impl fmt::Debug for ConstKind { } /// An unevaluated (potentially generic) constant used in the type-system. -#[derive_where(Clone, Copy, Debug, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Debug, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -74,6 +76,8 @@ pub struct UnevaluatedConst { pub args: I::GenericArgs, } +impl Eq for UnevaluatedConst {} + impl UnevaluatedConst { #[inline] pub fn new(def: I::DefId, args: I::GenericArgs) -> UnevaluatedConst { diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index 68b11489ae7c1..e8840bcfaca34 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -18,7 +18,7 @@ impl ExpectedFound { } // Data structures used in type unification -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic)] #[cfg_attr(feature = "nightly", rustc_pass_by_value)] pub enum TypeError { @@ -58,6 +58,8 @@ pub enum TypeError { TargetFeatureCast(I::DefId), } +impl Eq for TypeError {} + impl TypeError { pub fn involves_regions(self) -> bool { match self { diff --git a/compiler/rustc_type_ir/src/generic_arg.rs b/compiler/rustc_type_ir/src/generic_arg.rs index c18cade0e39bc..d6e33f724d0b2 100644 --- a/compiler/rustc_type_ir/src/generic_arg.rs +++ b/compiler/rustc_type_ir/src/generic_arg.rs @@ -4,7 +4,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContex use crate::Interner; -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -15,7 +15,9 @@ pub enum GenericArgKind { Const(I::Const), } -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +impl Eq for GenericArgKind {} + +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -24,3 +26,5 @@ pub enum TermKind { Ty(I::Ty), Const(I::Const), } + +impl Eq for TermKind {} diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs index e6462a97f8ab6..e39b99e992b03 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -18,7 +18,7 @@ use crate::{self as ty, Interner}; /// /// If neither of these functions are available, feel free to reach out to /// t-types for help. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -90,6 +90,8 @@ pub enum TypingMode { PostAnalysis, } +impl Eq for TypingMode {} + impl TypingMode { /// Analysis outside of a body does not define any opaque types. pub fn non_body_analysis() -> TypingMode { diff --git a/compiler/rustc_type_ir/src/opaque_ty.rs b/compiler/rustc_type_ir/src/opaque_ty.rs index 416d355fd03bd..b6fb9f28930f2 100644 --- a/compiler/rustc_type_ir/src/opaque_ty.rs +++ b/compiler/rustc_type_ir/src/opaque_ty.rs @@ -6,7 +6,7 @@ use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; use crate::inherent::*; use crate::{self as ty, Interner}; -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -17,6 +17,8 @@ pub struct OpaqueTypeKey { pub args: I::GenericArgs, } +impl Eq for OpaqueTypeKey {} + impl OpaqueTypeKey { pub fn iter_captured_args(self, cx: I) -> impl Iterator { let variances = cx.variances_of(self.def_id.into()); diff --git a/compiler/rustc_type_ir/src/pattern.rs b/compiler/rustc_type_ir/src/pattern.rs index 7e56565917c67..d757ac625f2db 100644 --- a/compiler/rustc_type_ir/src/pattern.rs +++ b/compiler/rustc_type_ir/src/pattern.rs @@ -5,7 +5,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen use crate::Interner; -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -15,3 +15,5 @@ pub enum PatternKind { Range { start: I::Const, end: I::Const }, Or(I::PatList), } + +impl Eq for PatternKind {} diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 9e4447ccd9939..1f67a03d7eaec 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -15,12 +15,8 @@ use crate::visit::TypeVisitableExt as _; use crate::{self as ty, Interner}; /// `A: 'region` -#[derive_where(Clone; I: Interner, A: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] #[derive_where(Copy; I: Interner, A: Copy)] -#[derive_where(Hash; I: Interner, A: Hash)] -#[derive_where(PartialEq; I: Interner, A: PartialEq)] -#[derive_where(Eq; I: Interner, A: Eq)] -#[derive_where(Debug; I: Interner, A: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -28,6 +24,8 @@ use crate::{self as ty, Interner}; )] pub struct OutlivesPredicate(pub A, pub I::Region); +impl Eq for OutlivesPredicate {} + // FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't // understand how to turn `A` to `A::Lifted` in the output `type Lifted`. impl Lift for OutlivesPredicate @@ -53,7 +51,7 @@ where /// /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the generic parameters. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -67,6 +65,8 @@ pub struct TraitRef { _use_trait_ref_new_instead: (), } +impl Eq for TraitRef {} + impl TraitRef { pub fn new_from_args(interner: I, trait_def_id: I::DefId, args: I::GenericArgs) -> Self { interner.debug_assert_args_compatible(trait_def_id, args); @@ -128,7 +128,7 @@ impl ty::Binder> { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -145,6 +145,8 @@ pub struct TraitPredicate { pub polarity: PredicatePolarity, } +impl Eq for TraitPredicate {} + impl TraitPredicate { pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { Self { @@ -271,7 +273,7 @@ impl fmt::Display for PredicatePolarity { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -286,6 +288,8 @@ pub enum ExistentialPredicate { AutoTrait(I::DefId), } +impl Eq for ExistentialPredicate {} + impl ty::Binder> { /// Given an existential predicate like `?Self: PartialEq` (e.g., derived from `dyn PartialEq`), /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` @@ -319,7 +323,7 @@ impl ty::Binder> { /// ``` /// The generic parameters don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -333,6 +337,8 @@ pub struct ExistentialTraitRef { _use_existential_trait_ref_new_instead: (), } +impl Eq for ExistentialTraitRef {} + impl ExistentialTraitRef { pub fn new_from_args(interner: I, trait_def_id: I::DefId, args: I::GenericArgs) -> Self { interner.debug_assert_existential_args_compatible(trait_def_id, args); @@ -386,7 +392,7 @@ impl ty::Binder> { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -402,6 +408,8 @@ pub struct ExistentialProjection { use_existential_projection_new_instead: (), } +impl Eq for ExistentialProjection {} + impl ExistentialProjection { pub fn new_from_args( interner: I, @@ -542,7 +550,7 @@ impl From for AliasTermKind { /// * For a projection, this would be `>::N<...>`. /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -578,6 +586,8 @@ pub struct AliasTerm { _use_alias_term_new_instead: (), } +impl Eq for AliasTerm {} + impl AliasTerm { pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm { interner.debug_assert_args_compatible(def_id, args); @@ -752,7 +762,7 @@ impl From> for AliasTerm { /// equality between arbitrary types. Processing an instance of /// Form #2 eventually yields one of these `ProjectionPredicate` /// instances to normalize the LHS. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -763,6 +773,8 @@ pub struct ProjectionPredicate { pub term: I::Term, } +impl Eq for ProjectionPredicate {} + impl ProjectionPredicate { pub fn self_ty(self) -> I::Ty { self.projection_term.self_ty() @@ -813,7 +825,7 @@ impl fmt::Debug for ProjectionPredicate { /// Used by the new solver to normalize an alias. This always expects the `term` to /// be an unconstrained inference variable which is used as the output. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -824,6 +836,8 @@ pub struct NormalizesTo { pub term: I::Term, } +impl Eq for NormalizesTo {} + impl NormalizesTo { pub fn self_ty(self) -> I::Ty { self.alias.self_ty() @@ -848,7 +862,7 @@ impl fmt::Debug for NormalizesTo { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -859,6 +873,8 @@ pub struct HostEffectPredicate { pub constness: BoundConstness, } +impl Eq for HostEffectPredicate {} + impl HostEffectPredicate { pub fn self_ty(self) -> I::Ty { self.trait_ref.self_ty() @@ -892,7 +908,7 @@ impl ty::Binder> { /// Encodes that `a` must be a subtype of `b`. The `a_is_expected` flag indicates /// whether the `a` type is the type that we should label as "expected" when /// presenting user diagnostics. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -904,8 +920,10 @@ pub struct SubtypePredicate { pub b: I::Ty, } +impl Eq for SubtypePredicate {} + /// Encodes that we have to coerce *from* the `a` type to the `b` type. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -916,6 +934,8 @@ pub struct CoercePredicate { pub b: I::Ty, } +impl Eq for CoercePredicate {} + #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)] #[cfg_attr( feature = "nightly", diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index 8bc15ec4ff557..ff92a0070cc5b 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -9,7 +9,7 @@ use crate::{self as ty, Interner}; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -55,7 +55,9 @@ pub enum ClauseKind { ), } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +impl Eq for ClauseKind {} + +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -109,6 +111,8 @@ pub enum PredicateKind { AliasRelate(I::Term, I::Term, AliasRelationDirection), } +impl Eq for PredicateKind {} + #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[cfg_attr( feature = "nightly", diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 1b5d04e6025fa..cca81dcb4a0b5 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -125,7 +125,7 @@ rustc_index::newtype_index! { /// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ /// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext))] pub enum RegionKind { /// A region parameter; for example `'a` in `impl<'a> Trait for &'a ()`. @@ -177,6 +177,8 @@ pub enum RegionKind { ReError(I::ErrorGuaranteed), } +impl Eq for RegionKind {} + impl fmt::Debug for RegionKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 3a00fe89360c6..223230fde9e72 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -33,7 +33,7 @@ pub enum StructurallyRelateAliases { /// a miscompilation or unsoundness. /// /// When in doubt, use `VarianceDiagInfo::default()` -#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug, Default; I: Interner)] pub enum VarianceDiagInfo { /// No additional information - this is the default. /// We will not add any additional information to error messages. @@ -51,6 +51,8 @@ pub enum VarianceDiagInfo { }, } +impl Eq for VarianceDiagInfo {} + impl VarianceDiagInfo { /// Mirrors `Variance::xform` - used to 'combine' the existing /// and new `VarianceDiagInfo`s when our variance changes. diff --git a/compiler/rustc_type_ir/src/solve/inspect.rs b/compiler/rustc_type_ir/src/solve/inspect.rs index 089695d0475e8..afb4043648f65 100644 --- a/compiler/rustc_type_ir/src/solve/inspect.rs +++ b/compiler/rustc_type_ir/src/solve/inspect.rs @@ -17,9 +17,6 @@ //! //! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html -use std::fmt::Debug; -use std::hash::Hash; - use derive_where::derive_where; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -32,25 +29,23 @@ use crate::{Canonical, CanonicalVarValues, Interner}; /// This is only ever used as [CanonicalState]. Any type information in proof /// trees used mechanically has to be canonicalized as we otherwise leak /// inference variables from a nested `InferCtxt`. -#[derive_where(Clone; I: Interner, T: Clone)] +#[derive_where(Clone, PartialEq, Hash, Debug; I: Interner, T)] #[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(Debug; I: Interner, T: Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct State { pub var_values: CanonicalVarValues, pub data: T, } +impl Eq for State {} + pub type CanonicalState = Canonical>; /// When evaluating a goal we also store the original values /// for the `CanonicalVarValues` of the canonicalized goal. /// We use this to map any [CanonicalState] from the local `InferCtxt` /// of the solver query to the `InferCtxt` of the caller. -#[derive_where(PartialEq, Eq, Hash; I: Interner)] +#[derive_where(PartialEq, Hash; I: Interner)] pub struct GoalEvaluation { pub uncanonicalized_goal: Goal, pub orig_values: Vec, @@ -58,7 +53,9 @@ pub struct GoalEvaluation { pub result: QueryResult, } -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +impl Eq for GoalEvaluation {} + +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub enum GoalEvaluationKind { Overflow, Evaluation { @@ -67,10 +64,12 @@ pub enum GoalEvaluationKind { }, } +impl Eq for GoalEvaluationKind {} + /// A self-contained computation during trait solving. This either /// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation /// of a goal. -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub struct Probe { /// What happened inside of this probe in chronological order. pub steps: Vec>, @@ -78,7 +77,9 @@ pub struct Probe { pub final_state: CanonicalState, } -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +impl Eq for Probe {} + +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub enum ProbeStep { /// We added a goal to the `EvalCtxt` which will get proven /// the next time `EvalCtxt::try_evaluate_added_goals` is called. @@ -97,10 +98,12 @@ pub enum ProbeStep { MakeCanonicalResponse { shallow_certainty: Certainty }, } +impl Eq for ProbeStep {} + /// What kind of probe we're in. In case the probe represents a candidate, or /// the final result of the current goal - via [ProbeKind::Root] - we also /// store the [QueryResult]. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub enum ProbeKind { /// The root inference context while proving a goal. @@ -125,3 +128,5 @@ pub enum ProbeKind { /// Checking that a rigid alias is well-formed. RigidAlias { result: QueryResult }, } + +impl Eq for ProbeKind {} diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index a6571ef261a16..1497236039f3f 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -1,6 +1,5 @@ pub mod inspect; -use std::fmt; use std::hash::Hash; use derive_where::derive_where; @@ -32,12 +31,8 @@ pub struct NoSolution; /// /// Most of the time the `param_env` contains the `where`-bounds of the function /// we're currently typechecking while the `predicate` is some trait bound. -#[derive_where(Clone; I: Interner, P: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, P)] #[derive_where(Copy; I: Interner, P: Copy)] -#[derive_where(Hash; I: Interner, P: Hash)] -#[derive_where(PartialEq; I: Interner, P: PartialEq)] -#[derive_where(Eq; I: Interner, P: Eq)] -#[derive_where(Debug; I: Interner, P: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -48,6 +43,8 @@ pub struct Goal { pub predicate: P, } +impl Eq for Goal {} + impl Goal { pub fn new(cx: I, param_env: I::ParamEnv, predicate: impl Upcast) -> Goal { Goal { param_env, predicate: predicate.upcast(cx) } @@ -98,12 +95,8 @@ pub enum GoalSource { NormalizeGoal(PathKind), } -#[derive_where(Clone; I: Interner, Goal: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, Goal)] #[derive_where(Copy; I: Interner, Goal: Copy)] -#[derive_where(Hash; I: Interner, Goal: Hash)] -#[derive_where(PartialEq; I: Interner, Goal: PartialEq)] -#[derive_where(Eq; I: Interner, Goal: Eq)] -#[derive_where(Debug; I: Interner, Goal: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -114,8 +107,10 @@ pub struct QueryInput { pub predefined_opaques_in_body: I::PredefinedOpaques, } +impl Eq for QueryInput {} + /// Opaques that are defined in the inference context before a query is called. -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -125,8 +120,10 @@ pub struct PredefinedOpaquesData { pub opaque_types: Vec<(ty::OpaqueTypeKey, I::Ty)>, } +impl Eq for PredefinedOpaquesData {} + /// Possible ways the given goal can be proven. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] pub enum CandidateSource { /// A user written impl. /// @@ -189,6 +186,8 @@ pub enum CandidateSource { CoherenceUnknowable, } +impl Eq for CandidateSource {} + #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)] pub enum ParamEnvSource { /// Preferred eagerly. @@ -217,7 +216,7 @@ pub enum BuiltinImplSource { TraitUpcasting(usize), } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct Response { @@ -227,8 +226,10 @@ pub struct Response { pub external_constraints: I::ExternalConstraints, } +impl Eq for Response {} + /// Additional constraints returned on success. -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct ExternalConstraintsData { @@ -237,6 +238,8 @@ pub struct ExternalConstraintsData { pub normalization_nested_goals: NestedNormalizationGoals, } +impl Eq for ExternalConstraintsData {} + impl ExternalConstraintsData { pub fn is_empty(&self) -> bool { self.region_constraints.is_empty() @@ -245,11 +248,13 @@ impl ExternalConstraintsData { } } -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct NestedNormalizationGoals(pub Vec<(GoalSource, Goal)>); +impl Eq for NestedNormalizationGoals {} + impl NestedNormalizationGoals { pub fn empty() -> Self { NestedNormalizationGoals(vec![]) diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 73aeab5092df0..bde506ffd9385 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -69,7 +69,7 @@ impl AliasTyKind { /// Types written by the user start out as `hir::TyKind` and get /// converted to this representation using `::lower_ty`. #[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")] -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -268,6 +268,8 @@ pub enum TyKind { Error(I::ErrorGuaranteed), } +impl Eq for TyKind {} + impl TyKind { pub fn fn_sig(self, interner: I) -> ty::Binder> { match self { @@ -404,7 +406,7 @@ impl fmt::Debug for TyKind { /// * For a projection, this would be `>::N<...>`. /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -440,6 +442,8 @@ pub struct AliasTy { pub(crate) _use_alias_ty_new_instead: (), } +impl Eq for AliasTy {} + impl AliasTy { pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTy { interner.debug_assert_args_compatible(def_id, args); @@ -720,7 +724,7 @@ impl fmt::Debug for InferTy { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -731,7 +735,9 @@ pub struct TypeAndMut { pub mutbl: Mutability, } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] +impl Eq for TypeAndMut {} + +#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -748,6 +754,8 @@ pub struct FnSig { pub abi: I::Abi, } +impl Eq for FnSig {} + impl FnSig { pub fn inputs(self) -> I::FnInputTys { self.inputs_and_output.inputs() @@ -845,11 +853,13 @@ impl fmt::Debug for FnSig { // FIXME: this is a distinct type because we need to define `Encode`/`Decode` // impls in this crate for `Binder`. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct UnsafeBinderInner(ty::Binder); +impl Eq for UnsafeBinderInner {} + impl From> for UnsafeBinderInner { fn from(value: ty::Binder) -> Self { UnsafeBinderInner(value) @@ -906,7 +916,7 @@ where } // This is just a `FnSig` without the `FnHeader` fields. -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -916,6 +926,8 @@ pub struct FnSigTys { pub inputs_and_output: I::Tys, } +impl Eq for FnSigTys {} + impl FnSigTys { pub fn inputs(self) -> I::FnInputTys { self.inputs_and_output.inputs() @@ -958,7 +970,7 @@ impl ty::Binder> { } } -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -970,7 +982,9 @@ pub struct FnHeader { pub abi: I::Abi, } -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +impl Eq for FnHeader {} + +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -980,3 +994,5 @@ pub struct CoroutineWitnessTypes { pub types: I::Tys, pub assumptions: I::RegionAssumptions, } + +impl Eq for CoroutineWitnessTypes {} diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index c32f8339d0b75..a2e16d917a9e9 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -101,7 +101,7 @@ use crate::{self as ty, Interner}; /// `yield` inside the coroutine. /// * `GR`: The "return type", which is the type of value returned upon /// completion of the coroutine. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct ClosureArgs { /// Lifetime and type parameters from the enclosing function, @@ -112,6 +112,8 @@ pub struct ClosureArgs { pub args: I::GenericArgs, } +impl Eq for ClosureArgs {} + /// Struct returned by `split()`. pub struct ClosureArgsParts { /// This is the args of the typeck root. @@ -203,12 +205,14 @@ impl ClosureArgs { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct CoroutineClosureArgs { pub args: I::GenericArgs, } +impl Eq for CoroutineClosureArgs {} + /// See docs for explanation of how each argument is used. /// /// See [`CoroutineClosureSignature`] for how these arguments are put together @@ -348,7 +352,7 @@ impl TypeVisitor for HasRegionsBoundAt { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct CoroutineClosureSignature { pub tupled_inputs_ty: I::Ty, @@ -371,6 +375,8 @@ pub struct CoroutineClosureSignature { pub abi: I::Abi, } +impl Eq for CoroutineClosureSignature {} + impl CoroutineClosureSignature { /// Construct a coroutine from the closure signature. Since a coroutine signature /// is agnostic to the type of generator that is returned (by-ref/by-move), @@ -541,7 +547,7 @@ impl TypeFolder for FoldEscapingRegions { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct GenSig { pub resume_ty: I::Ty, @@ -549,13 +555,16 @@ pub struct GenSig { pub return_ty: I::Ty, } +impl Eq for GenSig {} /// Similar to `ClosureArgs`; see the above documentation for more. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct CoroutineArgs { pub args: I::GenericArgs, } +impl Eq for CoroutineArgs {} + pub struct CoroutineArgsParts { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice,