Skip to content

Commit 91d75ea

Browse files
committed
Switch more impls to derives (implicitly adding #[inline])
1 parent 3a2ab93 commit 91d75ea

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

compiler/rustc_hir/src/hir_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt;
1111
/// the `local_id` part of the `HirId` changing, which is a very useful property in
1212
/// incremental compilation where we have to persist things through changes to
1313
/// the code base.
14-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
14+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStableEq)]
1515
#[derive(Encodable, Decodable)]
1616
pub struct HirId {
1717
pub owner: LocalDefId,

compiler/rustc_hir/src/stable_hash_impls.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rustc_data_structures::stable_hasher::{
2-
HashStable, HashStableEq, StableHasher, ToStableHashKey,
3-
};
1+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
42

53
use crate::hir::{
64
AttributeMap, BodyId, Crate, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item,
@@ -35,12 +33,6 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
3533
}
3634
}
3735

38-
impl HashStableEq for HirId {
39-
fn hash_stable_eq(&self, other: &HirId) -> bool {
40-
self == other
41-
}
42-
}
43-
4436
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemLocalId {
4537
type KeyType = ItemLocalId;
4638

compiler/rustc_span/src/def_id.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::HashStableContext;
22
use rustc_data_structures::fingerprint::Fingerprint;
3-
use rustc_data_structures::stable_hasher::{
4-
HashStable, HashStableEq, StableHasher, ToStableHashKey,
5-
};
3+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
64
use rustc_data_structures::AtomicRef;
75
use rustc_index::vec::Idx;
86
use rustc_macros::HashStable_Generic;
@@ -222,7 +220,7 @@ impl<D: Decoder> Decodable<D> for DefIndex {
222220
/// index and a def index.
223221
///
224222
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
225-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
223+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy, HashStableEq)]
226224
// On below-64 bit systems we can simply use the derived `Hash` impl
227225
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
228226
#[repr(C)]
@@ -238,12 +236,6 @@ pub struct DefId {
238236
pub index: DefIndex,
239237
}
240238

241-
impl HashStableEq for DefId {
242-
fn hash_stable_eq(&self, other: &Self) -> bool {
243-
self == other
244-
}
245-
}
246-
247239
// On 64-bit systems, we can hash the whole `DefId` as one `u64` instead of two `u32`s. This
248240
// improves performance without impairing `FxHash` quality. So the below code gets compiled to a
249241
// noop on little endian systems because the memory layout of `DefId` is as follows:

compiler/rustc_type_ir/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate bitflags;
55
#[macro_use]
66
extern crate rustc_macros;
77

8-
use rustc_data_structures::stable_hasher::{HashStable, HashStableEq, StableHasher};
8+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99
use rustc_data_structures::unify::{EqUnifyValue, UnifyKey};
1010
use std::fmt;
1111
use std::mem::discriminant;
@@ -449,7 +449,7 @@ impl UnifyKey for FloatVid {
449449
}
450450
}
451451

452-
#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash)]
452+
#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash, HashStableEq)]
453453
pub enum Variance {
454454
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
455455
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
@@ -560,12 +560,6 @@ impl<CTX> HashStable<CTX> for Variance {
560560
}
561561
}
562562

563-
impl HashStableEq for Variance {
564-
fn hash_stable_eq(&self, other: &Self) -> bool {
565-
self == other
566-
}
567-
}
568-
569563
impl fmt::Debug for IntVarValue {
570564
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
571565
match *self {

0 commit comments

Comments
 (0)