From dc95bd69f24474032123e371a4059f5502de3309 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 21 Mar 2024 13:10:28 +0000 Subject: [PATCH] Remove `Ord` from `Ty`, `Const`, and `Region` --- compiler/rustc_middle/src/thir.rs | 6 ++- compiler/rustc_middle/src/ty/consts.rs | 4 +- compiler/rustc_middle/src/ty/consts/kind.rs | 4 +- compiler/rustc_middle/src/ty/generic_args.rs | 15 +----- compiler/rustc_middle/src/ty/mod.rs | 6 +-- compiler/rustc_middle/src/ty/predicate.rs | 8 +-- compiler/rustc_middle/src/ty/region.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 6 +-- compiler/rustc_type_ir/src/const_kind.rs | 10 +--- compiler/rustc_type_ir/src/interner.rs | 54 ++++++++++---------- compiler/rustc_type_ir/src/region_kind.rs | 10 +--- compiler/rustc_type_ir/src/ty_kind.rs | 12 +---- 12 files changed, 51 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index f684f83a261..966d4ff4368 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -1018,7 +1018,11 @@ impl<'tcx> PatRangeBoundary<'tcx> { (Finite(mir::Const::Ty(a)), Finite(mir::Const::Ty(b))) if matches!(ty.kind(), ty::Uint(_) | ty::Char) => { - return Some(a.kind().cmp(&b.kind())); + if let Some(a) = a.try_to_valtree() { + if let Some(b) = b.try_to_valtree() { + return Some(a.cmp(&b)); + } + } } ( Finite(mir::Const::Val(mir::ConstValue::Scalar(Scalar::Int(a)), _)), diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 0d621cd1cfd..3713883eb00 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -23,7 +23,7 @@ pub use valtree::*; pub type ConstKind<'tcx> = IrConstKind>; /// Use this rather than `ConstData`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_pass_by_value] pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo>>); @@ -52,7 +52,7 @@ impl<'tcx> ConstTy> for Const<'tcx> { } /// Typed constant value. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(HashStable, TyEncodable, TyDecodable)] pub struct ConstData<'tcx> { pub ty: Ty<'tcx>, diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index 705987d92fe..ea02faca5f3 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId; use rustc_macros::HashStable; /// An unevaluated (potentially generic) constant used in the type-system. -#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, Eq, PartialEq, TyEncodable, TyDecodable)] #[derive(Hash, HashStable, TypeFoldable, TypeVisitable)] pub struct UnevaluatedConst<'tcx> { pub def: DefId, @@ -62,7 +62,7 @@ impl<'tcx> UnevaluatedConst<'tcx> { } } -#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Eq, PartialEq, Hash)] #[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)] pub enum Expr<'tcx> { Binop(mir::BinOp, Const<'tcx>, Const<'tcx>), diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 02b58c035d4..19cef927faf 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -17,7 +17,6 @@ use rustc_type_ir::WithCachedTypeInfo; use smallvec::SmallVec; use core::intrinsics; -use std::cmp::Ordering; use std::marker::PhantomData; use std::mem; use std::num::NonZero; @@ -68,7 +67,7 @@ const TYPE_TAG: usize = 0b00; const REGION_TAG: usize = 0b01; const CONST_TAG: usize = 0b10; -#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)] +#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, HashStable)] pub enum GenericArgKind<'tcx> { Lifetime(ty::Region<'tcx>), Type(Ty<'tcx>), @@ -100,18 +99,6 @@ impl<'tcx> GenericArgKind<'tcx> { } } -impl<'tcx> Ord for GenericArg<'tcx> { - fn cmp(&self, other: &GenericArg<'tcx>) -> Ordering { - self.unpack().cmp(&other.unpack()) - } -} - -impl<'tcx> PartialOrd for GenericArg<'tcx> { - fn partial_cmp(&self, other: &GenericArg<'tcx>) -> Option { - Some(self.cmp(other)) - } -} - impl<'tcx> From> for GenericArg<'tcx> { #[inline] fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index aad2f6a4cf8..d1d8a3ea072 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -517,7 +517,7 @@ pub struct CReaderCacheKey { } /// Use this rather than `TyKind`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_diagnostic_item = "Ty"] #[rustc_pass_by_value] pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo>>); @@ -702,7 +702,7 @@ const TAG_MASK: usize = 0b11; const TYPE_TAG: usize = 0b00; const CONST_TAG: usize = 0b01; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable)] pub enum TermKind<'tcx> { Ty(Ty<'tcx>), @@ -980,7 +980,7 @@ impl PlaceholderLike for PlaceholderType { } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] -#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)] +#[derive(TyEncodable, TyDecodable)] pub struct BoundConst<'tcx> { pub var: BoundVar, pub ty: Ty<'tcx>, diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index d3bc7dd22e7..05156dd5205 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -192,7 +192,7 @@ impl<'tcx> Clause<'tcx> { } } -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub enum ExistentialPredicate<'tcx> { /// E.g., `Iterator`. @@ -336,7 +336,7 @@ impl<'tcx> ty::List> { /// /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the generic parameters. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct TraitRef<'tcx> { pub def_id: DefId, @@ -420,7 +420,7 @@ impl<'tcx> IntoDiagArg for TraitRef<'tcx> { /// ``` /// The generic parameters don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, @@ -476,7 +476,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ExistentialProjection<'tcx> { pub def_id: DefId, diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index c66b9864e46..821642b8ab6 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -14,7 +14,7 @@ use crate::ty::{self, BoundVar, TyCtxt, TypeFlags}; pub type RegionKind<'tcx> = IrRegionKind>; /// Use this rather than `RegionKind`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_pass_by_value] pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>); diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 510a4b59520..a000c84696b 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1109,7 +1109,7 @@ where /// * 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(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct AliasTy<'tcx> { /// The parameters of the associated or opaque item. @@ -1278,7 +1278,7 @@ pub struct GenSig<'tcx> { /// - `inputs`: is the list of arguments and their modes. /// - `output`: is the return type. /// - `c_variadic`: indicates whether this is a C-variadic function. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, @@ -2661,7 +2661,7 @@ impl<'tcx> Ty<'tcx> { /// a miscompilation or unsoundness. /// /// When in doubt, use `VarianceDiagInfo::default()` -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub enum VarianceDiagInfo<'tcx> { /// No additional information - this is the default. /// We will not add any additional information to error messages. diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 0aaaad5af05..5b08140db3a 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -8,15 +8,7 @@ use self::ConstKind::*; /// Represents a constant in Rust. #[derive(derivative::Derivative)] -#[derivative( - Clone(bound = ""), - Copy(bound = ""), - PartialOrd(bound = ""), - PartialOrd = "feature_allow_slow_enum", - Ord(bound = ""), - Ord = "feature_allow_slow_enum", - Hash(bound = "") -)] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))] pub enum ConstKind { /// A const generic parameter. diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 373540de05e..bd67fdbfb2b 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -10,15 +10,15 @@ use crate::{ pub trait Interner: Sized { type DefId: Copy + Debug + Hash + Ord; - type AdtDef: Copy + Debug + Hash + Ord; + type AdtDef: Copy + Debug + Hash + Eq; type GenericArgs: Copy + DebugWithInfcx + Hash - + Ord + + Eq + IntoIterator; - type GenericArg: Copy + DebugWithInfcx + Hash + Ord; - type Term: Copy + Debug + Hash + Ord; + type GenericArg: Copy + DebugWithInfcx + Hash + Eq; + type Term: Copy + Debug + Hash + Eq; type Binder>: BoundVars + TypeSuperVisitable; type BoundVars: IntoIterator; @@ -30,56 +30,56 @@ pub trait Interner: Sized { type Ty: Copy + DebugWithInfcx + Hash - + Ord + + Eq + Into + IntoKind> + TypeSuperVisitable + Flags + new::Ty; - type Tys: Copy + Debug + Hash + Ord + IntoIterator; - type AliasTy: Copy + DebugWithInfcx + Hash + Ord; - type ParamTy: Copy + Debug + Hash + Ord; - type BoundTy: Copy + Debug + Hash + Ord; - type PlaceholderTy: Copy + Debug + Hash + Ord + PlaceholderLike; + type Tys: Copy + Debug + Hash + Eq + IntoIterator; + type AliasTy: Copy + DebugWithInfcx + Hash + Eq; + type ParamTy: Copy + Debug + Hash + Eq; + type BoundTy: Copy + Debug + Hash + Eq; + type PlaceholderTy: Copy + Debug + Hash + Eq + PlaceholderLike; // Things stored inside of tys - type ErrorGuaranteed: Copy + Debug + Hash + Ord; - type BoundExistentialPredicates: Copy + DebugWithInfcx + Hash + Ord; - type PolyFnSig: Copy + DebugWithInfcx + Hash + Ord; - type AllocId: Copy + Debug + Hash + Ord; + type ErrorGuaranteed: Copy + Debug + Hash + Eq; + type BoundExistentialPredicates: Copy + DebugWithInfcx + Hash + Eq; + type PolyFnSig: Copy + DebugWithInfcx + Hash + Eq; + type AllocId: Copy + Debug + Hash + Eq; // Kinds of consts type Const: Copy + DebugWithInfcx + Hash - + Ord + + Eq + Into + IntoKind> + ConstTy + TypeSuperVisitable + Flags + new::Const; - type AliasConst: Copy + DebugWithInfcx + Hash + Ord; - type PlaceholderConst: Copy + Debug + Hash + Ord + PlaceholderLike; - type ParamConst: Copy + Debug + Hash + Ord; - type BoundConst: Copy + Debug + Hash + Ord; - type ValueConst: Copy + Debug + Hash + Ord; - type ExprConst: Copy + DebugWithInfcx + Hash + Ord; + type AliasConst: Copy + DebugWithInfcx + Hash + Eq; + type PlaceholderConst: Copy + Debug + Hash + Eq + PlaceholderLike; + type ParamConst: Copy + Debug + Hash + Eq; + type BoundConst: Copy + Debug + Hash + Eq; + type ValueConst: Copy + Debug + Hash + Eq; + type ExprConst: Copy + DebugWithInfcx + Hash + Eq; // Kinds of regions type Region: Copy + DebugWithInfcx + Hash - + Ord + + Eq + Into + IntoKind> + Flags + new::Region; - type EarlyParamRegion: Copy + Debug + Hash + Ord; - type LateParamRegion: Copy + Debug + Hash + Ord; - type BoundRegion: Copy + Debug + Hash + Ord; - type InferRegion: Copy + DebugWithInfcx + Hash + Ord; - type PlaceholderRegion: Copy + Debug + Hash + Ord + PlaceholderLike; + type EarlyParamRegion: Copy + Debug + Hash + Eq; + type LateParamRegion: Copy + Debug + Hash + Eq; + type BoundRegion: Copy + Debug + Hash + Eq; + type InferRegion: Copy + DebugWithInfcx + Hash + Eq; + type PlaceholderRegion: Copy + Debug + Hash + Eq + PlaceholderLike; // Predicates type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable + Flags; diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 2e8481df56d..e1247e2661a 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -113,15 +113,7 @@ use self::RegionKind::*; /// [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(derivative::Derivative)] -#[derivative( - Clone(bound = ""), - Copy(bound = ""), - PartialOrd(bound = ""), - PartialOrd = "feature_allow_slow_enum", - Ord(bound = ""), - Ord = "feature_allow_slow_enum", - Hash(bound = "") -)] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable))] pub enum RegionKind { /// A region parameter; for example `'a` in `impl<'a> Trait for &'a ()`. diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 5ed73cd94f4..fad67fe3cbb 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -63,15 +63,7 @@ impl AliasKind { /// converted to this representation using `::lower_ty`. #[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")] #[derive(derivative::Derivative)] -#[derivative( - Clone(bound = ""), - Copy(bound = ""), - PartialOrd(bound = ""), - PartialOrd = "feature_allow_slow_enum", - Ord(bound = ""), - Ord = "feature_allow_slow_enum", - Hash(bound = "") -)] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))] pub enum TyKind { /// The primitive boolean type. Written as `bool`. @@ -803,8 +795,6 @@ impl DebugWithInfcx for InferTy { #[derivative( Clone(bound = ""), Copy(bound = ""), - PartialOrd(bound = ""), - Ord(bound = ""), PartialEq(bound = ""), Eq(bound = ""), Hash(bound = ""),