Skip to content

Commit

Permalink
Rollup merge of #92442 - pierwill:localdefid-doc-ord, r=Aaron1011
Browse files Browse the repository at this point in the history
Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`

Suggested in #92233 (comment).

This also fixes some formatting in the doc comment.

r? `@cjgillot`
  • Loading branch information
matthiaskrgr authored Jan 5, 2022
2 parents 84e48a4 + 0bac713 commit bf9546c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,23 @@ impl fmt::Debug for DefId {

rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);

/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since
/// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since
/// we encode this information in the type, we can ensure at compile time that
/// no DefIds from upstream crates get thrown into the mix. There are quite a
/// few cases where we know that only DefIds from the local crate are expected
/// and a DefId from a different crate would signify a bug somewhere. This
/// is when LocalDefId comes in handy.
/// no `DefId`s from upstream crates get thrown into the mix. There are quite a
/// few cases where we know that only `DefId`s from the local crate are expected;
/// a `DefId` from a different crate would signify a bug somewhere. This
/// is when `LocalDefId` comes in handy.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalDefId {
pub local_def_index: DefIndex,
}

// To ensure correctness of incremental compilation,
// `LocalDefId` must not implement `Ord` or `PartialOrd`.
// See https://github.com/rust-lang/rust/issues/90317.
impl !Ord for LocalDefId {}
impl !PartialOrd for LocalDefId {}

pub const CRATE_DEF_ID: LocalDefId = LocalDefId { local_def_index: CRATE_DEF_INDEX };

impl Idx for LocalDefId {
Expand Down

0 comments on commit bf9546c

Please sign in to comment.