Replace no_ord_impl with orderable.

Similar to the previous commit, this replaces `newtype_index`'s opt-out
`no_ord_impl` attribute with the opt-in `orderable` attribute.
This commit is contained in:
Nicholas Nethercote 2023-11-21 17:35:46 +11:00
parent 3ef9d4d0ed
commit 7060fc8327
28 changed files with 43 additions and 4 deletions

View File

@ -2574,6 +2574,7 @@ pub enum AttrStyle {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "AttrId({})"] #[debug_format = "AttrId({})"]
pub struct AttrId {} pub struct AttrId {}
} }

View File

@ -9,6 +9,7 @@ rustc_index::newtype_index! {
/// ///
/// [`DefId`]: rustc_span::def_id::DefId /// [`DefId`]: rustc_span::def_id::DefId
#[encodable] #[encodable]
#[orderable]
#[debug_format = "NodeId({})"] #[debug_format = "NodeId({})"]
pub struct NodeId { pub struct NodeId {
/// The [`NodeId`] used to represent the root of the crate. /// The [`NodeId`] used to represent the root of the crate.

View File

@ -122,6 +122,7 @@ rustc_index::newtype_index! {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "ConstraintSccIndex({})"] #[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex {} pub struct ConstraintSccIndex {}
} }

View File

@ -109,6 +109,7 @@ impl_visitable! {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "bw{}"] #[debug_format = "bw{}"]
pub struct BorrowIndex {} pub struct BorrowIndex {}
} }

View File

@ -20,6 +20,7 @@ pub struct LocationTable {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "LocationIndex({})"] #[debug_format = "LocationIndex({})"]
pub struct LocationIndex {} pub struct LocationIndex {}
} }

View File

@ -90,6 +90,7 @@ impl RegionValueElements {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A single integer representing a `Location` in the MIR control-flow /// A single integer representing a `Location` in the MIR control-flow
/// graph. Constructed efficiently from `RegionValueElements`. /// graph. Constructed efficiently from `RegionValueElements`.
#[orderable]
#[debug_format = "PointIndex({})"] #[debug_format = "PointIndex({})"]
pub struct PointIndex {} pub struct PointIndex {}
} }

View File

@ -23,6 +23,7 @@ struct PreOrderFrame<Iter> {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
struct PreorderIndex {} struct PreorderIndex {}
} }

View File

@ -155,6 +155,7 @@ rustc_index::newtype_index! {
/// tree or hash map. /// tree or hash map.
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
#[encodable] #[encodable]
#[orderable]
pub struct ItemLocalId {} pub struct ItemLocalId {}
} }

View File

@ -198,6 +198,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
// entire graph when there are many connected regions. // entire graph when there are many connected regions.
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
pub struct RegionId {} pub struct RegionId {}
} }

View File

@ -4,11 +4,13 @@ use rustc_middle::ty::error::TypeError;
use std::cmp; use std::cmp;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "ExpectedIdx({})"] #[debug_format = "ExpectedIdx({})"]
pub(crate) struct ExpectedIdx {} pub(crate) struct ExpectedIdx {}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "ProvidedIdx({})"] #[debug_format = "ProvidedIdx({})"]
pub(crate) struct ProvidedIdx {} pub(crate) struct ProvidedIdx {}
} }

View File

@ -2,6 +2,7 @@
use crate as rustc_index; use crate as rustc_index;
crate::newtype_index! { crate::newtype_index! {
#[orderable]
#[max = 0xFFFF_FFFA] #[max = 0xFFFF_FFFA]
struct MyIdx {} struct MyIdx {}
} }

View File

@ -23,7 +23,7 @@ impl Parse for Newtype {
let mut max = None; let mut max = None;
let mut consts = Vec::new(); let mut consts = Vec::new();
let mut encodable = false; let mut encodable = false;
let mut ord = true; let mut ord = false;
let mut gate_rustc_only = quote! {}; let mut gate_rustc_only = quote! {};
let mut gate_rustc_only_cfg = quote! { all() }; let mut gate_rustc_only_cfg = quote! { all() };
@ -38,8 +38,8 @@ impl Parse for Newtype {
encodable = true; encodable = true;
false false
} }
"no_ord_impl" => { "orderable" => {
ord = false; ord = true;
false false
} }
"max" => { "max" => {

View File

@ -341,11 +341,13 @@ impl<'tcx> SccUniverse<'tcx> {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "LeakCheckNode({})"] #[debug_format = "LeakCheckNode({})"]
struct LeakCheckNode {} struct LeakCheckNode {}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "LeakCheckScc({})"] #[debug_format = "LeakCheckScc({})"]
struct LeakCheckScc {} struct LeakCheckScc {}
} }

View File

@ -149,6 +149,7 @@ rustc_index::newtype_index! {
/// and thus does not include EXPR_2, but covers the `...`. /// and thus does not include EXPR_2, but covers the `...`.
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
pub struct FirstStatementIndex {} pub struct FirstStatementIndex {}
} }

View File

@ -18,6 +18,7 @@ rustc_index::newtype_index! {
/// to use a larger representation on the Rust side. /// to use a larger representation on the Rust side.
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "CounterId({})"] #[debug_format = "CounterId({})"]
pub struct CounterId {} pub struct CounterId {}
@ -39,6 +40,7 @@ rustc_index::newtype_index! {
/// to use a larger representation on the Rust side. /// to use a larger representation on the Rust side.
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "ExpressionId({})"] #[debug_format = "ExpressionId({})"]
pub struct ExpressionId {} pub struct ExpressionId {}

View File

@ -737,6 +737,7 @@ impl SourceInfo {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "_{}"] #[debug_format = "_{}"]
pub struct Local { pub struct Local {
const RETURN_PLACE = 0; const RETURN_PLACE = 0;
@ -1173,6 +1174,7 @@ rustc_index::newtype_index! {
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/ /// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "bb{}"] #[debug_format = "bb{}"]
pub struct BasicBlock { pub struct BasicBlock {
const START_BLOCK = 0; const START_BLOCK = 0;
@ -1537,6 +1539,7 @@ impl UserTypeProjection {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "promoted[{}]"] #[debug_format = "promoted[{}]"]
pub struct Promoted {} pub struct Promoted {}
} }

View File

@ -1613,6 +1613,7 @@ rustc_index::newtype_index! {
/// A **region** (lifetime) **v**ariable **ID**. /// A **region** (lifetime) **v**ariable **ID**.
#[derive(HashStable)] #[derive(HashStable)]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "'?{}"] #[debug_format = "'?{}"]
pub struct RegionVid {} pub struct RegionVid {}
} }

View File

@ -186,6 +186,7 @@ pub(crate) enum BreakableTarget {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
struct DropIdx {} struct DropIdx {}
} }

View File

@ -14,6 +14,7 @@ use self::abs_domain::{AbstractElem, Lift};
mod abs_domain; mod abs_domain;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "mp{}"] #[debug_format = "mp{}"]
pub struct MovePathIndex {} pub struct MovePathIndex {}
} }
@ -25,6 +26,7 @@ impl polonius_engine::Atom for MovePathIndex {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "mo{}"] #[debug_format = "mo{}"]
pub struct MoveOutIndex {} pub struct MoveOutIndex {}
} }

View File

@ -264,6 +264,7 @@ impl graph::WithPredecessors for CoverageGraph {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A node in the control-flow graph of CoverageGraph. /// A node in the control-flow graph of CoverageGraph.
#[orderable]
#[debug_format = "bcb{}"] #[debug_format = "bcb{}"]
pub(super) struct BasicCoverageBlock { pub(super) struct BasicCoverageBlock {
const START_BCB = 0; const START_BCB = 0;

View File

@ -13,6 +13,7 @@ pub type StableCrateIdMap =
indexmap::IndexMap<StableCrateId, CrateNum, BuildHasherDefault<Unhasher>>; indexmap::IndexMap<StableCrateId, CrateNum, BuildHasherDefault<Unhasher>>;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
#[debug_format = "crate{}"] #[debug_format = "crate{}"]
pub struct CrateNum {} pub struct CrateNum {}
} }
@ -212,6 +213,7 @@ rustc_index::newtype_index! {
/// A DefIndex is an index into the hir-map for a crate, identifying a /// A DefIndex is an index into the hir-map for a crate, identifying a
/// particular definition. It should really be considered an interned /// particular definition. It should really be considered an interned
/// shorthand for a particular DefPath. /// shorthand for a particular DefPath.
#[orderable]
#[debug_format = "DefIndex({})"] #[debug_format = "DefIndex({})"]
pub struct DefIndex { pub struct DefIndex {
/// The crate root is always assigned index 0 by the AST Map code, /// The crate root is always assigned index 0 by the AST Map code,

View File

@ -60,6 +60,7 @@ pub struct SyntaxContextData {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A unique ID associated with a macro invocation and expansion. /// A unique ID associated with a macro invocation and expansion.
#[orderable]
pub struct ExpnIndex {} pub struct ExpnIndex {}
} }
@ -79,7 +80,6 @@ impl fmt::Debug for ExpnId {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A unique ID associated with a macro invocation and expansion. /// A unique ID associated with a macro invocation and expansion.
#[no_ord_impl]
#[debug_format = "expn{}"] #[debug_format = "expn{}"]
pub struct LocalExpnId {} pub struct LocalExpnId {}
} }

View File

@ -2018,6 +2018,7 @@ impl fmt::Display for MacroRulesNormalizedIdent {
pub struct Symbol(SymbolIndex); pub struct Symbol(SymbolIndex);
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
struct SymbolIndex {} struct SymbolIndex {}
} }

View File

@ -43,6 +43,7 @@ rustc_index::newtype_index! {
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`. /// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
#[encodable] #[encodable]
#[orderable]
pub struct FieldIdx {} pub struct FieldIdx {}
} }
@ -59,6 +60,7 @@ rustc_index::newtype_index! {
/// with variant index zero, aka [`FIRST_VARIANT`]. /// with variant index zero, aka [`FIRST_VARIANT`].
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
#[encodable] #[encodable]
#[orderable]
pub struct VariantIdx { pub struct VariantIdx {
/// Equivalent to `VariantIdx(0)`. /// Equivalent to `VariantIdx(0)`.
const FIRST_VARIANT = 0; const FIRST_VARIANT = 0;

View File

@ -13,6 +13,7 @@ use rustc_session::Limit;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[orderable]
pub struct StackDepth {} pub struct StackDepth {}
} }

View File

@ -96,6 +96,7 @@ impl<I: Interner> DebugWithInfcx<I> for ConstKind<I> {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A **`const`** **v**ariable **ID**. /// A **`const`** **v**ariable **ID**.
#[encodable] #[encodable]
#[orderable]
#[debug_format = "?{}c"] #[debug_format = "?{}c"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct ConstVid {} pub struct ConstVid {}
@ -110,6 +111,7 @@ rustc_index::newtype_index! {
/// where we are not correctly using the effect var for an effect param. Fallback /// where we are not correctly using the effect var for an effect param. Fallback
/// is also implemented on top of having separate effect and normal const variables. /// is also implemented on top of having separate effect and normal const variables.
#[encodable] #[encodable]
#[orderable]
#[debug_format = "?{}e"] #[debug_format = "?{}e"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct EffectVid {} pub struct EffectVid {}

View File

@ -93,6 +93,7 @@ rustc_index::newtype_index! {
/// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index /// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "DebruijnIndex({})"] #[debug_format = "DebruijnIndex({})"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct DebruijnIndex { pub struct DebruijnIndex {
@ -295,6 +296,7 @@ rustc_index::newtype_index! {
/// use for checking generic functions. /// use for checking generic functions.
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "U{}"] #[debug_format = "U{}"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct UniverseIndex {} pub struct UniverseIndex {}
@ -338,6 +340,7 @@ impl UniverseIndex {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[encodable] #[encodable]
#[orderable]
#[debug_format = "{}"] #[debug_format = "{}"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct BoundVar {} pub struct BoundVar {}

View File

@ -623,6 +623,7 @@ pub struct FloatVarValue(pub FloatTy);
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A **ty**pe **v**ariable **ID**. /// A **ty**pe **v**ariable **ID**.
#[encodable] #[encodable]
#[orderable]
#[debug_format = "?{}t"] #[debug_format = "?{}t"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct TyVid {} pub struct TyVid {}
@ -631,6 +632,7 @@ rustc_index::newtype_index! {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
#[encodable] #[encodable]
#[orderable]
#[debug_format = "?{}i"] #[debug_format = "?{}i"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct IntVid {} pub struct IntVid {}
@ -639,6 +641,7 @@ rustc_index::newtype_index! {
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**. /// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
#[encodable] #[encodable]
#[orderable]
#[debug_format = "?{}f"] #[debug_format = "?{}f"]
#[gate_rustc_only] #[gate_rustc_only]
pub struct FloatVid {} pub struct FloatVid {}