Skip to content

Commit bf9546c

Browse files
authored
Rollup merge of #92442 - pierwill:localdefid-doc-ord, r=Aaron1011
Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId` Suggested in #92233 (comment). This also fixes some formatting in the doc comment. r? `@cjgillot`
2 parents 84e48a4 + 0bac713 commit bf9546c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

compiler/rustc_span/src/def_id.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,23 @@ impl fmt::Debug for DefId {
316316

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

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

330+
// To ensure correctness of incremental compilation,
331+
// `LocalDefId` must not implement `Ord` or `PartialOrd`.
332+
// See https://github.com/rust-lang/rust/issues/90317.
333+
impl !Ord for LocalDefId {}
334+
impl !PartialOrd for LocalDefId {}
335+
330336
pub const CRATE_DEF_ID: LocalDefId = LocalDefId { local_def_index: CRATE_DEF_INDEX };
331337

332338
impl Idx for LocalDefId {

0 commit comments

Comments
 (0)