Remove unused ToStableHashKey impls.

There are quite a few.
This commit is contained in:
Nicholas Nethercote
2026-05-07 09:27:31 +10:00
parent e95e73209f
commit 769f2f16fe
11 changed files with 9 additions and 217 deletions
@@ -459,22 +459,6 @@ impl StableOrd for String {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl ToStableHashKey for String {
type KeyType = String;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
self.clone()
}
}
impl<T1: ToStableHashKey, T2: ToStableHashKey> ToStableHashKey for (T1, T2) {
type KeyType = (T1::KeyType, T2::KeyType);
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> Self::KeyType {
(self.0.to_stable_hash_key(hcx), self.1.to_stable_hash_key(hcx))
}
}
impl StableHash for bool {
#[inline]
fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
-10
View File
@@ -4,7 +4,6 @@
use rustc_ast as ast;
use rustc_ast::NodeId;
use rustc_data_structures::stable_hasher::ToStableHashKey;
use rustc_data_structures::unord::UnordMap;
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_macros::{Decodable, Encodable, StableHash};
@@ -712,15 +711,6 @@ fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
}
}
impl ToStableHashKey for Namespace {
type KeyType = Namespace;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Namespace {
*self
}
}
/// Just a helper separate structure for each namespace.
#[derive(Copy, Clone, Default, Debug, StableHash)]
pub struct PerNS<T> {
+2 -54
View File
@@ -1,59 +1,7 @@
use rustc_data_structures::stable_hasher::{
StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
};
use rustc_span::def_id::DefPathHash;
use rustc_data_structures::stable_hasher::{StableHash, StableHashCtxt, StableHasher};
use crate::HashIgnoredAttrId;
use crate::hir::{
AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
};
use crate::hir_id::ItemLocalId;
impl ToStableHashKey for BodyId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
let BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx)
}
}
impl ToStableHashKey for ItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl ToStableHashKey for TraitItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl ToStableHashKey for ImplItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl ToStableHashKey for ForeignItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
use crate::hir::{AttributeMap, OwnerNodes};
// The following implementations of StableHash for `ItemId`, `TraitItemId`, and
// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
-19
View File
@@ -176,22 +176,3 @@ impl StableOrd for ItemLocalId {
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO };
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
impl ToStableHashKey for HirId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
(def_path_hash, self.local_id)
}
}
impl ToStableHashKey for ItemLocalId {
type KeyType = ItemLocalId;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> ItemLocalId {
*self
}
}
+2 -29
View File
@@ -3,12 +3,11 @@
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::stable_hasher::{
StableCompare, StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
StableCompare, StableHash, StableHashCtxt, StableHasher,
};
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_hir_id::{HirId, ItemLocalId};
use rustc_hir_id::HirId;
use rustc_macros::{Decodable, Encodable, StableHash};
use rustc_span::def_id::DefPathHash;
pub use rustc_span::edition::Edition;
use rustc_span::{AttrId, Ident, Symbol, sym};
use serde::{Deserialize, Serialize};
@@ -154,23 +153,6 @@ fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHas
}
}
impl ToStableHashKey for LintExpectationId {
type KeyType = (DefPathHash, ItemLocalId, u16, u16);
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> Self::KeyType {
match self {
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx);
(def_path_hash, lint_idx, *attr_index, *lint_index)
}
_ => {
unreachable!("StableHash should only be called for a filled `LintExpectationId`")
}
}
}
}
/// Setting for how to handle a lint.
///
/// See: <https://doc.rust-lang.org/rustc/lints/levels.html>
@@ -623,15 +605,6 @@ fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHas
}
}
impl ToStableHashKey for LintId {
type KeyType = &'static str;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> &'static str {
self.lint_name_raw()
}
}
impl StableCompare for LintId {
const CAN_USE_UNSTABLE_SORT: bool = true;
@@ -51,7 +51,7 @@
use std::hash::Hash;
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey};
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd};
use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathHash;
use rustc_macros::{Decodable, Encodable, StableHash};
@@ -231,13 +231,7 @@ pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
WorkProductId { hash: hasher.finish() }
}
}
impl ToStableHashKey for WorkProductId {
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
self.hash
}
}
impl StableOrd for WorkProductId {
// Fingerprint can use unstable (just a tuple of `u64`s), so WorkProductId can as well
const CAN_USE_UNSTABLE_SORT: bool = true;
+1 -25
View File
@@ -7,11 +7,10 @@
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{
HashingControls, StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
HashingControls, StableHash, StableHashCtxt, StableHasher,
};
use tracing::trace;
use crate::middle::region;
use crate::{mir, ty};
impl<'tcx, H, T> StableHash for &'tcx ty::list::RawList<H, T>
@@ -45,20 +44,6 @@ fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHas
}
}
impl<'tcx, H, T> ToStableHashKey for &'tcx ty::list::RawList<H, T>
where
T: StableHash,
{
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> Fingerprint {
let mut hasher = StableHasher::new();
self.stable_hash(hcx, &mut hasher);
hasher.finish()
}
}
impl<'tcx> StableHash for ty::GenericArg<'tcx> {
fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.kind().stable_hash(hcx, hasher);
@@ -81,12 +66,3 @@ fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHas
self.into_parts().stable_hash(hcx, hasher);
}
}
impl ToStableHashKey for region::Scope {
type KeyType = region::Scope;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> region::Scope {
*self
}
}
+1 -11
View File
@@ -14,7 +14,7 @@
use externs::{ExternOpt, split_extern_opt};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey};
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd};
use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, DiagCtxtFlags};
use rustc_feature::UnstableFeatures;
@@ -628,7 +628,6 @@ pub enum OutputType {
)*
}
impl StableOrd for OutputType {
const CAN_USE_UNSTABLE_SORT: bool = true;
@@ -636,15 +635,6 @@ impl StableOrd for OutputType {
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
impl ToStableHashKey for OutputType {
type KeyType = Self;
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> Self::KeyType {
*self
}
}
impl OutputType {
pub fn iter_all() -> impl Iterator<Item = OutputType> {
static ALL_VARIANTS: &[OutputType] = &[
-18
View File
@@ -465,24 +465,6 @@ fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash
}
}
impl ToStableHashKey for CrateNum {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> DefPathHash {
self.as_def_id().to_stable_hash_key(hcx)
}
}
impl ToStableHashKey for DefPathHash {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> DefPathHash {
*self
}
}
macro_rules! typed_def_id {
($Name:ident, $LocalName:ident) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)]
+1 -9
View File
@@ -8,7 +8,7 @@
use rustc_arena::DroplessArena;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_data_structures::stable_hasher::{
StableCompare, StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
StableCompare, StableHash, StableHashCtxt, StableHasher,
};
use rustc_data_structures::sync::Lock;
use rustc_macros::{Decodable, Encodable, StableHash, symbols};
@@ -2639,14 +2639,6 @@ fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHas
}
}
impl ToStableHashKey for Symbol {
type KeyType = String;
#[inline]
fn to_stable_hash_key<Hcx>(&self, _: &mut Hcx) -> String {
self.as_str().to_string()
}
}
impl StableCompare for Symbol {
const CAN_USE_UNSTABLE_SORT: bool = true;
-18
View File
@@ -5,12 +5,6 @@
use rustc_ast_ir::Mutability;
#[cfg(feature = "nightly")]
use rustc_data_structures::fingerprint::Fingerprint;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{
StableHash, StableHashCtxt, StableHasher, ToStableHashKey,
};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
use crate::inherent::*;
@@ -48,18 +42,6 @@ pub enum SimplifiedType<DefId> {
Error,
}
#[cfg(feature = "nightly")]
impl<DefId: StableHash> ToStableHashKey for SimplifiedType<DefId> {
type KeyType = Fingerprint;
#[inline]
fn to_stable_hash_key<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx) -> Fingerprint {
let mut hasher = StableHasher::new();
self.stable_hash(hcx, &mut hasher);
hasher.finish()
}
}
/// Generic parameters are pretty much just bound variables, e.g.
/// the type of `fn foo<'a, T>(x: &'a T) -> u32 { ... }` can be thought of as
/// `for<'a, T> fn(&'a T) -> u32`.