Skip to content

Commit 076fc29

Browse files
committed
Remove ordering traits from HirId
Rm Ord from LintExpectationId Edit ToStableHashKey impl Impl Partialord for Level using discriminant
1 parent 049308c commit 076fc29

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

compiler/rustc_hir/src/hir_id.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ pub struct HirId {
1919
pub local_id: ItemLocalId,
2020
}
2121

22+
// To ensure correctness of incremental compilation,
23+
// `HirId` must not implement `Ord` or `PartialOrd`.
24+
// See https://github.com/rust-lang/rust/issues/90317.
25+
impl !Ord for HirId {}
26+
impl !PartialOrd for HirId {}
27+
2228
impl HirId {
2329
#[inline]
2430
pub fn expect_owner(self) -> LocalDefId {
@@ -40,10 +46,6 @@ impl HirId {
4046
pub fn make_owner(owner: LocalDefId) -> Self {
4147
Self { owner, local_id: ItemLocalId::from_u32(0) }
4248
}
43-
44-
pub fn index(self) -> (usize, usize) {
45-
(rustc_index::vec::Idx::index(self.owner), rustc_index::vec::Idx::index(self.local_id))
46-
}
4749
}
4850

4951
impl fmt::Display for HirId {
@@ -52,18 +54,6 @@ impl fmt::Display for HirId {
5254
}
5355
}
5456

55-
impl Ord for HirId {
56-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
57-
(self.index()).cmp(&(other.index()))
58-
}
59-
}
60-
61-
impl PartialOrd for HirId {
62-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
63-
Some(self.cmp(&other))
64-
}
65-
}
66-
6757
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
6858
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
6959

compiler/rustc_hir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(let_else)]
99
#![feature(once_cell)]
1010
#![feature(min_specialization)]
11+
#![feature(negative_impls)]
1112
#![feature(never_type)]
1213
#![feature(rustc_attrs)]
1314
#![recursion_limit = "256"]

compiler/rustc_lint_defs/src/lib.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#[macro_use]
44
extern crate rustc_macros;
55

6+
use std::cmp::Ordering;
7+
68
pub use self::Level::*;
79
use rustc_ast::node_id::{NodeId, NodeMap};
810
use rustc_ast::{AttrId, Attribute};
@@ -80,7 +82,7 @@ pub enum Applicability {
8082
/// The index values have a type of `u16` to reduce the size of the `LintExpectationId`.
8183
/// It's reasonable to assume that no user will define 2^16 attributes on one node or
8284
/// have that amount of lints listed. `u16` values should therefore suffice.
83-
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Encodable, Decodable)]
85+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Encodable, Decodable)]
8486
pub enum LintExpectationId {
8587
/// Used for lints emitted during the `EarlyLintPass`. This id is not
8688
/// hash stable and should not be cached.
@@ -134,13 +136,14 @@ impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
134136
}
135137

136138
impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
137-
type KeyType = (HirId, u16, u16);
139+
type KeyType = (rustc_hir::def_id::DefPathHash, rustc_hir::hir_id::ItemLocalId, u16, u16);
138140

139141
#[inline]
140-
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
142+
fn to_stable_hash_key(&self, hcx: &HCX) -> Self::KeyType {
141143
match self {
142144
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
143-
(*hir_id, *attr_index, *lint_index)
145+
let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx);
146+
(def_path_hash, lint_idx, *attr_index, *lint_index)
144147
}
145148
_ => {
146149
unreachable!("HashStable should only be called for a filled `LintExpectationId`")
@@ -152,7 +155,7 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
152155
/// Setting for how to handle a lint.
153156
///
154157
/// See: <https://doc.rust-lang.org/rustc/lints/levels.html>
155-
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable_Generic)]
158+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
156159
pub enum Level {
157160
/// The `allow` level will not issue any message.
158161
Allow,
@@ -186,6 +189,14 @@ pub enum Level {
186189
Forbid,
187190
}
188191

192+
impl PartialOrd for Level {
193+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
194+
std::mem::discriminant(self).partial_cmp(std::mem::discriminant(other))
195+
}
196+
}
197+
198+
rustc_data_structures::impl_stable_hash_via_hash!(Level);
199+
189200
impl Level {
190201
/// Converts a level to a lower-case string.
191202
pub fn as_str(self) -> &'static str {

compiler/rustc_middle/src/mir/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
350350
/// order of the category, thereby influencing diagnostic output.
351351
///
352352
/// See also `rustc_const_eval::borrow_check::constraints`.
353-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
353+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
354354
#[derive(TyEncodable, TyDecodable, HashStable)]
355355
pub enum ConstraintCategory<'tcx> {
356356
Return(ReturnConstraint),
@@ -392,7 +392,7 @@ pub enum ConstraintCategory<'tcx> {
392392
Internal,
393393
}
394394

395-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
395+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
396396
#[derive(TyEncodable, TyDecodable, HashStable)]
397397
pub enum ReturnConstraint {
398398
Normal,

compiler/rustc_typeck/src/check/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8585
/// Intermediate format to store the hir_id pointing to the use that resulted in the
8686
/// corresponding place being captured and a String which contains the captured value's
8787
/// name (i.e: a.b.c)
88-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
88+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
8989
enum UpvarMigrationInfo {
9090
/// We previously captured all of `x`, but now we capture some sub-path.
9191
CapturingPrecise { source_expr: Option<hir::HirId>, var_name: String },

0 commit comments

Comments
 (0)