Rollup merge of #154666 - nnethercote:rm-StableHashContext-impls, r=petrochenkov

Remove `StableHashContext` impls

Details in individual commits.

r? @petrochenkov
This commit is contained in:
Jonathan Brouwer
2026-04-02 22:13:50 +02:00
committed by GitHub
16 changed files with 50 additions and 80 deletions
-6
View File
@@ -67,12 +67,6 @@
#[cfg(feature = "nightly")]
pub use layout::{Layout, TyAbiInterface, TyAndLayout};
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
#[cfg(feature = "nightly")]
pub trait HashStableContext {}
#[derive(Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(
feature = "nightly",
+3 -2
View File
@@ -31,7 +31,8 @@
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
pub use rustc_span::AttrId;
use rustc_span::{
ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, respan, sym,
ByteSymbol, DUMMY_SP, ErrorGuaranteed, HashStableContext, Ident, Span, Spanned, Symbol, kw,
respan, sym,
};
use thin_vec::{ThinVec, thin_vec};
@@ -120,7 +121,7 @@ fn eq(&self, names: &&[Symbol]) -> bool {
}
}
impl<Hcx: rustc_span::HashStableContext> HashStable<Hcx> for Path {
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
-5
View File
@@ -36,8 +36,3 @@ pub mod util {
pub use self::ast::*;
pub use self::ast_traits::{AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_span::HashStableContext {}
+2 -2
View File
@@ -14,7 +14,7 @@
use rustc_data_structures::sync;
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
use rustc_serialize::{Decodable, Encodable};
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use rustc_span::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use thin_vec::ThinVec;
use crate::ast::AttrStyle;
@@ -826,7 +826,7 @@ fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
impl<Hcx> HashStable<Hcx> for TokenStream
where
Hcx: crate::HashStableContext,
Hcx: HashStableContext,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
for sub_tt in self.iter() {
+2 -2
View File
@@ -8,9 +8,9 @@
use rustc_data_structures::unord::UnordMap;
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::Symbol;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::hygiene::MacroKind;
use rustc_span::{HashStableContext, Symbol};
use crate::definitions::DefPathData;
use crate::hir;
@@ -712,7 +712,7 @@ fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
}
}
impl<Hcx: crate::HashStableContext> ToStableHashKey<Hcx> for Namespace {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for Namespace {
type KeyType = Namespace;
#[inline]
-1
View File
@@ -43,7 +43,6 @@
pub use lang_items::{LangItem, LanguageItems};
pub use rustc_ast::attr::version::*;
pub use stability::*;
pub use stable_hash_impls::HashStableContext;
pub use target::{MethodKind, Target};
arena_types!(rustc_arena::declare_arena);
+19 -23
View File
@@ -1,4 +1,5 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_span::HashStableContext;
use rustc_span::def_id::DefPathHash;
use crate::HashIgnoredAttrId;
@@ -8,53 +9,48 @@
use crate::hir_id::ItemLocalId;
use crate::lints::DelayedLints;
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStableContext {}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for BodyId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
fn to_stable_hash_key(&self, hcx: &Hcx) -> (DefPathHash, ItemLocalId) {
let BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx)
}
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for TraitItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ImplItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
type KeyType = DefPathHash;
#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
@@ -66,8 +62,8 @@ fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// We ignore the `nodes` and `bodies` fields since these refer to information included in
// `hash` which is hashed in the collector and used for the crate hash.
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
@@ -78,15 +74,15 @@ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for DelayedLints {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let DelayedLints { opt_hash, .. } = *self;
opt_hash.unwrap().hash_stable(hcx, hasher);
}
}
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// We ignore the `map` since it refers to information included in `opt_hash` which is
// hashed in the collector and used for the crate hash.
let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
@@ -94,8 +90,8 @@ fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HashIgnoredAttrId {
fn hash_stable(&self, _hcx: &mut HirCtx, _hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for HashIgnoredAttrId {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
/* we don't hash HashIgnoredAttrId, we ignore them */
}
}
+2 -2
View File
@@ -8,7 +8,7 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
pub use rustc_span::HashStableContext;
use rustc_span::HashStableContext;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId};
#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
@@ -176,7 +176,7 @@ impl StableOrd for ItemLocalId {
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
impl<Hcx: rustc_span::HashStableContext> ToStableHashKey<Hcx> for HirId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for HirId {
type KeyType = (DefPathHash, ItemLocalId);
#[inline]
+2 -2
View File
@@ -8,11 +8,11 @@
HashStable, StableCompare, StableHasher, ToStableHashKey,
};
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
use rustc_hir_id::{HirId, ItemLocalId};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::def_id::DefPathHash;
pub use rustc_span::edition::Edition;
use rustc_span::{Ident, Span, Symbol, sym};
use rustc_span::{HashStableContext, Ident, Span, Symbol, sym};
use serde::{Deserialize, Serialize};
pub use self::Level::*;
+1 -1
View File
@@ -84,7 +84,7 @@ fn hash_stable_derive_with_mode(
match mode {
HashStableMode::Normal => {}
HashStableMode::Generic => {
s.add_where_predicate(parse_quote! { __CTX: crate::HashStableContext });
s.add_where_predicate(parse_quote! { __CTX: ::rustc_span::HashStableContext });
}
HashStableMode::NoContext => {}
}
+3 -3
View File
@@ -21,7 +21,7 @@
use rustc_hir::*;
use rustc_index::IndexVec;
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
use rustc_span::{ErrorGuaranteed, ExpnId, HashStableContext, Span};
use crate::query::Providers;
use crate::ty::{ResolverAstLowering, TyCtxt};
@@ -77,8 +77,8 @@ pub fn owner(&self, tcx: TyCtxt<'hir>, def_id: LocalDefId) -> MaybeOwner<'hir> {
}
}
impl<HirCtx: HashStableContext> HashStable<HirCtx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let Crate { opt_hir_hash, .. } = self;
opt_hir_hash.unwrap().hash_stable(hcx, hasher)
}
+2 -7
View File
@@ -6,7 +6,7 @@
use rustc_session::Session;
use rustc_session::cstore::Untracked;
use rustc_span::source_map::SourceMap;
use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span};
use rustc_span::{CachingSourceMapView, DUMMY_SP, HashStableContext, Pos, Span};
// Very often, we are hashing something that does not need the `CachingSourceMapView`, so we
// initialize it lazily.
@@ -73,7 +73,7 @@ pub fn hashing_controls(&self) -> HashingControls {
}
}
impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
impl<'a> HashStableContext for StableHashingContext<'a> {
/// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that
/// would be similar to hashing pointers, since those are just offsets into the `SourceMap`).
/// Instead, we hash the (file name, line, column) triple, which stays the same even if the
@@ -189,8 +189,3 @@ fn assert_default_hashing_controls(&self, msg: &str) {
);
}
}
impl<'a> rustc_abi::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_ast::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_hir::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {}
+3 -2
View File
@@ -23,7 +23,8 @@
use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION};
use rustc_span::source_map::FilePathMapping;
use rustc_span::{
FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym,
FileName, HashStableContext, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm,
Symbol, sym,
};
use rustc_target::spec::{
FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo,
@@ -38,7 +39,7 @@
pub use crate::options::*;
use crate::search_paths::SearchPath;
use crate::utils::CanonicalizedPath;
use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint};
use crate::{EarlyDiagCtxt, Session, filesearch, lint};
mod cfg;
mod externs;
+7 -16
View File
@@ -11,30 +11,21 @@
#![recursion_limit = "256"]
// tidy-alphabetical-end
pub mod errors;
pub mod utils;
pub use getopts;
pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass};
pub use rustc_lint_defs as lint;
pub mod parse;
pub use session::*;
pub mod code_stats;
pub mod errors;
pub mod parse;
pub mod utils;
#[macro_use]
pub mod config;
pub mod cstore;
pub mod filesearch;
mod macros;
mod options;
pub mod search_paths;
mod session;
pub use session::*;
pub mod output;
pub use getopts;
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_ast::HashStableContext + rustc_hir::HashStableContext {}
pub mod search_paths;
mod session;
+4 -4
View File
@@ -2796,10 +2796,10 @@ pub fn new(start: usize, end: usize) -> InnerSpan {
}
}
/// Requirements for a `StableHashingContext` to be used in this crate.
///
/// This is a hack to allow using the [`HashStable_Generic`] derive macro
/// instead of implementing everything in rustc_middle.
/// This trait lets `HashStable` and `derive(HashStable_Generic)` be used in
/// this crate (and other crates upstream of `rustc_middle`), while leaving
/// certain operations to be defined in `rustc_middle` where more things are
/// visible.
pub trait HashStableContext {
/// The main event: stable hashing of a span.
fn span_hash_stable(&mut self, span: Span, hasher: &mut StableHasher);
-2
View File
@@ -24,8 +24,6 @@
#[cfg(test)]
mod tests;
use rustc_abi::HashStableContext;
/// The name of rustc's own place to organize libraries.
///
/// Used to be `rustc`, now the default is `rustlib`.