From 2eba51c733933731ef98bb939712d1d117c9b772 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 8 Apr 2026 15:58:19 +1000 Subject: [PATCH 1/7] Avoid `hcx.def_path_hash(def_id)` calls. `def_id.to_stable_hash_key(hcx)` calls `hcx.def_path_hash(def_id)`. This commit replaces various other occurrences of the latter form with the former form. It's all inlined so there should be no perf effects. This will make things easier for the next commit, which will change `DefId::to_stable_hash_key`. --- compiler/rustc_hir_id/src/lib.rs | 2 +- compiler/rustc_span/src/def_id.rs | 6 +++--- compiler/rustc_span/src/hygiene.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs index f37a19e9c1fe7..bebffeae22503 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -66,7 +66,7 @@ impl ToStableHashKey for OwnerId { #[inline] fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { - hcx.def_path_hash(self.to_def_id()) + self.to_def_id().to_stable_hash_key(hcx) } } diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 8a56d716a3003..c67aef6634b7d 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -405,14 +405,14 @@ rustc_data_structures::define_id_collections!( impl HashStable for DefId { #[inline] fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { - hcx.def_path_hash(*self).hash_stable(hcx, hasher); + self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } impl HashStable for LocalDefId { #[inline] fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { - hcx.def_path_hash(self.to_def_id()).local_hash().hash_stable(hcx, hasher); + self.to_stable_hash_key(hcx).local_hash().hash_stable(hcx, hasher); } } @@ -437,7 +437,7 @@ impl ToStableHashKey for LocalDefId { #[inline] fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { - hcx.def_path_hash(self.to_def_id()) + self.to_def_id().to_stable_hash_key(hcx) } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index e7b98cc910973..ac4588d0c8078 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -30,7 +30,7 @@ use std::{fmt, iter, mem}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use rustc_data_structures::sync::Lock; use rustc_data_structures::unhash::UnhashMap; use rustc_hashes::Hash64; @@ -1514,7 +1514,7 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContex }); } - ExpnHash::new(hcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(), expn_hash) + ExpnHash::new(LOCAL_CRATE.as_def_id().to_stable_hash_key(&mut hcx).stable_crate_id(), expn_hash) } impl HashStable for SyntaxContext { From 7b0c3d4e1e514a1541488c912218ac246cc3e24c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 2 Apr 2026 19:41:57 +1100 Subject: [PATCH 2/7] Move `HashStableContext` trait to `rustc_data_structures`. This puts it in the same crate as the `HashStable` and `ToStableHasher` traits. This requires introducing three types `RawSpan`, `RawDefId` and `RawDefPathHash` to work around the fact that `rustc_data_structures` is upstream of `rustc_span` and so doesn't have access to `Span`, `DefId`, and `DefPathHash`. This is a bit ugly but is worth it because moving `HashStableContext` enables big cleanups across many crates in subsequent commits. --- compiler/rustc_ast/src/ast.rs | 5 ++- compiler/rustc_ast/src/tokenstream.rs | 4 +-- .../src/stable_hasher.rs | 34 ++++++++++++++++++ compiler/rustc_hir/src/def.rs | 4 +-- compiler/rustc_hir/src/stable_hash_impls.rs | 5 +-- compiler/rustc_hir_id/src/lib.rs | 5 +-- compiler/rustc_lint_defs/src/lib.rs | 4 +-- compiler/rustc_macros/src/hash_stable.rs | 4 ++- compiler/rustc_middle/src/hir/mod.rs | 4 +-- compiler/rustc_middle/src/ich/hcx.rs | 14 +++++--- compiler/rustc_session/src/config.rs | 7 ++-- compiler/rustc_span/src/def_id.rs | 35 +++++++++++++++++-- compiler/rustc_span/src/hygiene.rs | 6 ++-- compiler/rustc_span/src/lib.rs | 21 ++--------- compiler/rustc_span/src/span_encoding.rs | 14 ++++++++ 15 files changed, 119 insertions(+), 47 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ae4989fcbc6c9..72fcf042e6743 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -25,14 +25,13 @@ pub use GenericArgs::*; pub use UnsafeSource::*; pub use rustc_ast_ir::{FloatTy, IntTy, Movability, Mutability, Pinnedness, UintTy}; use rustc_data_structures::packed::Pu128; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::tagged_ptr::Tag; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; pub use rustc_span::AttrId; use rustc_span::{ - ByteSymbol, DUMMY_SP, ErrorGuaranteed, HashStableContext, Ident, Span, Spanned, Symbol, kw, - respan, sym, + ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, respan, sym, }; use thin_vec::{ThinVec, thin_vec}; diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 06bd6f03e9350..ec3a226added3 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -10,11 +10,11 @@ use std::ops::Range; use std::sync::Arc; use std::{cmp, fmt, iter, mem}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::sync; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; use rustc_serialize::{Decodable, Encodable}; -use rustc_span::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, Symbol, sym}; +use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym}; use thin_vec::ThinVec; use crate::ast::AttrStyle; diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index ce3d781712515..1ef86768eb504 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -15,6 +15,40 @@ pub use rustc_stable_hash::{ FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher, }; +/// 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: RawSpan, hasher: &mut StableHasher); + + /// Compute a `DefPathHash`. + fn def_path_hash(&self, def_id: RawDefId) -> RawDefPathHash; + + /// Assert that the provided `HashStableContext` is configured with the default + /// `HashingControls`. We should always have bailed out before getting to here with a + fn assert_default_hashing_controls(&self, msg: &str); +} + +// A type used to work around `Span` not being visible in this crate. It is the same size as +// `Span`. +pub struct RawSpan { + _data: u64, +} + +// A type used to work around `DefId` not being visible in this crate. It is the same size as +// `DefId`. +pub struct RawDefId { + _data: u64, +} + +// A type used to work around `DefPathHash` not being visible in this crate. It is the same size as +// `DefPathHash`. +pub struct RawDefPathHash { + _data: u128, +} + /// Something that implements `HashStable` can be hashed in a way that is /// stable across multiple compilation sessions. /// diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index ec701cbe9a469..0cf8a67727840 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -4,13 +4,13 @@ use std::fmt::Debug; use rustc_ast as ast; use rustc_ast::NodeId; -use rustc_data_structures::stable_hasher::ToStableHashKey; +use rustc_data_structures::stable_hasher::{HashStableContext, ToStableHashKey}; 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; diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index f2cfeaf027f3b..5cccbb821bfbf 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,5 +1,6 @@ -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; -use rustc_span::HashStableContext; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, ToStableHashKey, +}; use rustc_span::def_id::DefPathHash; use crate::HashIgnoredAttrId; diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs index bebffeae22503..2f44aba439f4d 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -6,9 +6,10 @@ use std::fmt::{self, Debug}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, StableOrd, ToStableHashKey, +}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -use rustc_span::HashStableContext; use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 36070dac276fb..596e2979c676b 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -3,14 +3,14 @@ use std::fmt::Display; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::stable_hasher::{ - HashStable, StableCompare, StableHasher, ToStableHashKey, + HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey, }; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; 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::{AttrId, HashStableContext, Ident, Span, Symbol, sym}; +use rustc_span::{AttrId, Ident, Span, Symbol, sym}; use serde::{Deserialize, Serialize}; pub use self::Level::*; diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index adb93e375c32c..709f5ccc2a2ad 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -84,7 +84,9 @@ fn hash_stable_derive_with_mode( match mode { HashStableMode::Normal => {} HashStableMode::Generic => { - s.add_where_predicate(parse_quote! { __CTX: ::rustc_span::HashStableContext }); + s.add_where_predicate(parse_quote! { + __CTX: ::rustc_data_structures::stable_hasher::HashStableContext + }); } HashStableMode::NoContext => {} } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 814b333cfb0f8..8fe65ea5ad12c 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -12,7 +12,7 @@ use rustc_ast::{self as ast}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::sorted_map::SortedMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in}; use rustc_hir::def::{DefKind, Res}; @@ -21,7 +21,7 @@ use rustc_hir::lints::DelayedLint; use rustc_hir::*; use rustc_index::IndexVec; use rustc_macros::{Decodable, Encodable, HashStable}; -use rustc_span::{ErrorGuaranteed, ExpnId, HashStableContext, Span}; +use rustc_span::{ErrorGuaranteed, ExpnId, Span}; use crate::query::Providers; use crate::ty::{ResolverAstLowering, TyCtxt}; diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index e316cbc81bebe..af4bef46c1cc2 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -1,12 +1,13 @@ use std::hash::Hash; -use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, HashingControls, RawDefId, RawDefPathHash, RawSpan, StableHasher, +}; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::definitions::DefPathHash; use rustc_session::Session; use rustc_session::cstore::Untracked; use rustc_span::source_map::SourceMap; -use rustc_span::{CachingSourceMapView, DUMMY_SP, HashStableContext, Pos, Span}; +use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span}; // Very often, we are hashing something that does not need the `CachingSourceMapView`, so we // initialize it lazily. @@ -84,7 +85,7 @@ impl<'a> HashStableContext for StableHashingContext<'a> { /// /// IMPORTANT: changes to this method should be reflected in implementations of `SpanEncoder`. #[inline] - fn span_hash_stable(&mut self, span: Span, hasher: &mut StableHasher) { + fn span_hash_stable(&mut self, raw_span: RawSpan, hasher: &mut StableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; const TAG_RELATIVE_SPAN: u8 = 2; @@ -93,6 +94,7 @@ impl<'a> HashStableContext for StableHashingContext<'a> { return; } + let span = Span::from_raw_span(raw_span); let span = span.data_untracked(); span.ctxt.hash_stable(self, hasher); span.parent.hash_stable(self, hasher); @@ -157,12 +159,14 @@ impl<'a> HashStableContext for StableHashingContext<'a> { } #[inline] - fn def_path_hash(&self, def_id: DefId) -> DefPathHash { + fn def_path_hash(&self, raw_def_id: RawDefId) -> RawDefPathHash { + let def_id = DefId::from_raw_def_id(raw_def_id); if let Some(def_id) = def_id.as_local() { self.untracked.definitions.read().def_path_hash(def_id) } else { self.untracked.cstore.read().def_path_hash(def_id) } + .to_raw_def_path_hash() } /// Assert that the provided `HashStableContext` is configured with the default diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index e4ef1d40d72d5..7aafe657ffa1f 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -14,7 +14,9 @@ use std::{cmp, fs, iter}; 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::{ + HashStableContext, StableHasher, StableOrd, ToStableHashKey, +}; use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::{ColorConfig, DiagCtxtFlags}; use rustc_feature::UnstableFeatures; @@ -23,8 +25,7 @@ use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable_Generic}; use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION}; use rustc_span::source_map::FilePathMapping; use rustc_span::{ - FileName, HashStableContext, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, - Symbol, sym, + FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym, }; use rustc_target::spec::{ FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo, diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index c67aef6634b7d..bf50fa2889cf0 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -3,14 +3,17 @@ use std::hash::{BuildHasherDefault, Hash, Hasher}; use rustc_data_structures::AtomicRef; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, RawDefId, RawDefPathHash, StableHasher, StableOrd, + ToStableHashKey, +}; use rustc_data_structures::unhash::Unhasher; use rustc_hashes::Hash64; use rustc_index::Idx; use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable_Generic}; use rustc_serialize::{Decodable, Encodable}; -use crate::{HashStableContext, SpanDecoder, SpanEncoder, Symbol}; +use crate::{SpanDecoder, SpanEncoder, Symbol}; pub type StableCrateIdMap = indexmap::IndexMap>; @@ -114,6 +117,19 @@ impl DefPathHash { pub fn new(stable_crate_id: StableCrateId, local_hash: Hash64) -> DefPathHash { DefPathHash(Fingerprint::new(stable_crate_id.0, local_hash)) } + + #[inline] + pub fn to_raw_def_path_hash(self) -> RawDefPathHash { + // SAFETY: we call `to_raw_def_path_hash` and then `from_raw_def_path_hash` immediately + // after, only when returning from `HashStableContext::def_path_hash`. + unsafe { std::mem::transmute::(self) } + } + + #[inline] + pub fn from_raw_def_path_hash(raw_def_path_hash: RawDefPathHash) -> DefPathHash { + // SAFETY: see the comment in `to_raw_def_path_hash`. + unsafe { std::mem::transmute::(raw_def_path_hash) } + } } impl Default for DefPathHash { @@ -312,6 +328,19 @@ impl DefId { pub fn is_top_level_module(self) -> bool { self.is_local() && self.is_crate_root() } + + #[inline] + pub fn to_raw_def_id(self) -> RawDefId { + // SAFETY: we call `to_raw_def_id` and then `from_raw_def_id` immediately after, only when + // calling `HashStableContext::def_path_hash`. + unsafe { std::mem::transmute::(self) } + } + + #[inline] + pub fn from_raw_def_id(raw_def_id: RawDefId) -> DefId { + // SAFETY: see the comment in `to_raw_def_id`. + unsafe { std::mem::transmute::(raw_def_id) } + } } impl From for DefId { @@ -428,7 +457,7 @@ impl ToStableHashKey for DefId { #[inline] fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { - hcx.def_path_hash(*self) + DefPathHash::from_raw_def_path_hash(hcx.def_path_hash(self.to_raw_def_id())) } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index ac4588d0c8078..c59643eeacadc 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -30,7 +30,9 @@ use std::{fmt, iter, mem}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, ToStableHashKey, +}; use rustc_data_structures::sync::Lock; use rustc_data_structures::unhash::UnhashMap; use rustc_hashes::Hash64; @@ -43,7 +45,7 @@ use crate::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, StableCrateId}; use crate::edition::Edition; use crate::source_map::SourceMap; use crate::symbol::{Symbol, kw, sym}; -use crate::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, with_session_globals}; +use crate::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, with_session_globals}; /// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". /// diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 97de708290fb4..daa9b54ba7c8e 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -31,6 +31,7 @@ extern crate self as rustc_span; use derive_where::derive_where; +use rustc_data_structures::stable_hasher::HashStableContext; use rustc_data_structures::{AtomicRef, outline}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::opaque::{FileEncoder, MemDecoder}; @@ -53,7 +54,7 @@ pub use hygiene::{ DesugaringKind, ExpnData, ExpnHash, ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext, }; pub mod def_id; -use def_id::{CrateNum, DefId, DefIndex, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId}; +use def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, StableCrateId}; pub mod edit_distance; mod span_encoding; pub use span_encoding::{DUMMY_SP, Span}; @@ -2796,29 +2797,13 @@ impl InnerSpan { } } -/// 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); - - /// Compute a `DefPathHash`. - fn def_path_hash(&self, def_id: DefId) -> DefPathHash; - - /// Assert that the provided `HashStableContext` is configured with the default - /// `HashingControls`. We should always have bailed out before getting to here with a - fn assert_default_hashing_controls(&self, msg: &str); -} - impl HashStable for Span where Hcx: HashStableContext, { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { // `span_hash_stable` does all the work. - hcx.span_hash_stable(*self, hasher) + hcx.span_hash_stable(self.to_raw_span(), hasher) } } diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index e34efa784dee6..43bd1046ba581 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -1,4 +1,5 @@ use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::stable_hasher::RawSpan; // This code is very hot and uses lots of arithmetic, avoid overflow checks for performance. // See https://github.com/rust-lang/rust/pull/119440#issuecomment-1874255727 use rustc_serialize::int_overflow::DebugStrictAdd; @@ -441,6 +442,19 @@ impl Span { Interned(span) => interned_parent(span.index), } } + + #[inline] + pub(crate) fn to_raw_span(self) -> RawSpan { + // SAFETY: we call `to_raw_span` and then `from_raw_span` immediately after, only when + // calling `HashStableContext::span_hash_stable`. + unsafe { std::mem::transmute::(self) } + } + + #[inline] + pub fn from_raw_span(raw_span: RawSpan) -> Span { + // SAFETY: see the comment in `to_raw_span`. + unsafe { std::mem::transmute::(raw_span) } + } } #[derive(Default)] From c991ac01147b064788517008b0acc96142a2c181 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Apr 2026 14:08:20 +1100 Subject: [PATCH 3/7] Overhaul stable hashing traits. `std::hash::Hash` looks like this: ``` pub trait Hash { fn hash(&self, state: &mut H) where H: Hasher; ... } ``` The method is generic. In contrast, `HashStable` looks like this: ``` pub trait HashStable { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); } ``` and impls look like this (in crates upstream of `rustc_middle`): ``` impl HashStable for Path { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { ... } } ``` or this (in `rustc_middle` and crates downstream of `rustc_middle`): ``` impl<'tcx> HashStable> for rustc_feature::Features { fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { ... } } ``` Differences to `std::hash::Hash`: - The trait is generic, rather than the method. - The way impls are written depends their position in the crate graph. - This explains why we have both `derive(HashStable)` and `derive(HashStable_Generic)`. The former is for the downstream-of-`rustc_middle` case, the latter is for the upstream of `rustc_middle` case. Why the differences? It all boils down to `HashStable` and `HashStableContext` being in different crates. But the previous commit fixed that, which means `HashStable` can be simplified to this, with a generic method: ``` pub trait HashStable { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); } ``` and all impls look like this: ``` impl HashStable for Path { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { ... } } ``` Other consequences: - `derive(HashStable_Generic)` is no longer needed; `derive(HashStable)` can be used instead. - In this commit, `derive(HashStable_Generic` is made a synonym of `derive(HashStable)`. The next commit will remove this synonym, because it's a change that touches many lines. - `#[stable_hash_generic]` is no longer needed (for `newtype_index`); `#[stable_hash]` can be used instead. - `#[stable_hash_no_context]` was already a synonym of `#[stable_hash_generic]`, so it's also removed in favour of just `#[stable_hash]`. - The difference between `derive(HashStable)` and `derive(HashStable_NoContext)` now comes down to the difference between `synstructure::AddBounds::Generics` and `synstructure::AddBounds::Fields`, which is basically "vanilla derive" vs "(near) perfect derive". - I have improved the comments on `HashStableMode` to better explaining this subtle difference. - `rustc_middle/src/ich/impls_syntax.rs` is no longer needed; the relevant impls can be defined in the crate that defines the relevant type. - Occurrences of `for<'a> HashStable>` are replaced with with `HashStable`, hooray. - The commit adds a `HashStableContext::hashing_controls` method, which is no big deal. Overall this is a big simplification, removing a lots of confusing complexity in stable hashing traits. --- compiler/rustc_abi/src/extern_abi.rs | 8 +- compiler/rustc_abi/src/layout.rs | 4 +- compiler/rustc_ast/src/ast.rs | 4 +- compiler/rustc_ast/src/node_id.rs | 8 + compiler/rustc_ast/src/tokenstream.rs | 11 +- .../rustc_codegen_cranelift/src/driver/aot.rs | 6 +- compiler/rustc_codegen_ssa/src/common.rs | 6 +- compiler/rustc_data_structures/src/intern.rs | 8 +- compiler/rustc_data_structures/src/packed.rs | 6 +- .../rustc_data_structures/src/sorted_map.rs | 6 +- .../src/stable_hasher.rs | 225 +++++++++--------- .../src/stable_hasher/tests.rs | 29 ++- compiler/rustc_data_structures/src/steal.rs | 6 +- .../rustc_data_structures/src/tagged_ptr.rs | 10 +- .../src/tagged_ptr/tests.rs | 8 +- compiler/rustc_data_structures/src/unord.rs | 45 ++-- compiler/rustc_feature/src/unstable.rs | 27 +++ compiler/rustc_hir/src/def.rs | 6 +- compiler/rustc_hir/src/hir.rs | 2 +- compiler/rustc_hir/src/lang_items.rs | 6 +- compiler/rustc_hir/src/stable_hash_impls.rs | 39 +-- compiler/rustc_hir_id/src/lib.rs | 21 +- compiler/rustc_index_macros/src/newtype.rs | 29 +-- compiler/rustc_lint_defs/src/lib.rs | 16 +- compiler/rustc_macros/src/hash_stable.rs | 70 ++---- compiler/rustc_macros/src/lib.rs | 14 +- .../rustc_middle/src/dep_graph/dep_node.rs | 4 +- .../src/dep_graph/dep_node_key.rs | 3 +- compiler/rustc_middle/src/dep_graph/graph.rs | 2 +- compiler/rustc_middle/src/hir/mod.rs | 4 +- compiler/rustc_middle/src/ich/hcx.rs | 5 + compiler/rustc_middle/src/ich/impls_syntax.rs | 81 ------- compiler/rustc_middle/src/ich/mod.rs | 1 - compiler/rustc_middle/src/middle/privacy.rs | 7 +- compiler/rustc_middle/src/mir/basic_blocks.rs | 6 +- compiler/rustc_middle/src/mono.rs | 13 +- compiler/rustc_middle/src/query/keys.rs | 3 +- compiler/rustc_middle/src/ty/adt.rs | 9 +- compiler/rustc_middle/src/ty/consts/int.rs | 9 +- compiler/rustc_middle/src/ty/context.rs | 6 +- compiler/rustc_middle/src/ty/impls_ty.rs | 31 ++- compiler/rustc_middle/src/ty/mod.rs | 7 +- compiler/rustc_session/src/config.rs | 8 +- compiler/rustc_span/src/def_id.rs | 28 +-- compiler/rustc_span/src/hygiene.rs | 12 +- compiler/rustc_span/src/lib.rs | 7 +- compiler/rustc_span/src/symbol.rs | 14 +- compiler/rustc_type_ir/src/const_kind.rs | 6 +- compiler/rustc_type_ir/src/fast_reject.rs | 8 +- compiler/rustc_type_ir/src/lib.rs | 6 +- compiler/rustc_type_ir/src/region_kind.rs | 16 +- compiler/rustc_type_ir/src/ty_info.rs | 6 +- compiler/rustc_type_ir/src/ty_kind.rs | 6 +- 53 files changed, 445 insertions(+), 483 deletions(-) delete mode 100644 compiler/rustc_middle/src/ich/impls_syntax.rs diff --git a/compiler/rustc_abi/src/extern_abi.rs b/compiler/rustc_abi/src/extern_abi.rs index 9173245d8aa4e..2b03589d7314d 100644 --- a/compiler/rustc_abi/src/extern_abi.rs +++ b/compiler/rustc_abi/src/extern_abi.rs @@ -3,7 +3,9 @@ use std::fmt; use std::hash::{Hash, Hasher}; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, StableOrd, +}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable, Encodable}; #[cfg(feature = "nightly")] @@ -217,9 +219,9 @@ impl Hash for ExternAbi { } #[cfg(feature = "nightly")] -impl HashStable for ExternAbi { +impl HashStable for ExternAbi { #[inline] - fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { Hash::hash(self, hasher); } } diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index cca1d499088f4..3aa00d14d39b1 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -45,7 +45,7 @@ rustc_index::newtype_index! { /// `b` is `FieldIdx(1)` in `VariantIdx(0)`, /// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and /// `f` is `FieldIdx(1)` in `VariantIdx(0)`. - #[stable_hash_generic] + #[stable_hash] #[encodable] #[orderable] #[gate_rustc_only] @@ -70,7 +70,7 @@ rustc_index::newtype_index! { /// /// `struct`s, `tuples`, and `unions`s are considered to have a single variant /// with variant index zero, aka [`FIRST_VARIANT`]. - #[stable_hash_generic] + #[stable_hash] #[encodable] #[orderable] #[gate_rustc_only] diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 72fcf042e6743..d62af54647aa7 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -120,8 +120,8 @@ impl PartialEq<&[Symbol]> for Path { } } -impl HashStable for Path { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for Path { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.segments.len().hash_stable(hcx, hasher); for segment in &self.segments { segment.ident.hash_stable(hcx, hasher); diff --git a/compiler/rustc_ast/src/node_id.rs b/compiler/rustc_ast/src/node_id.rs index adca1844b61f8..848fbc1848c0b 100644 --- a/compiler/rustc_ast/src/node_id.rs +++ b/compiler/rustc_ast/src/node_id.rs @@ -1,5 +1,6 @@ use std::fmt; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_span::LocalExpnId; rustc_index::newtype_index! { @@ -18,6 +19,13 @@ rustc_index::newtype_index! { } } +impl HashStable for NodeId { + #[inline] + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { + panic!("Node IDs should not appear in incremental state"); + } +} + rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId); /// When parsing and at the beginning of doing expansions, we initially give all AST nodes diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index ec3a226added3..efd9b500ea0e1 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -138,8 +138,8 @@ impl Decodable for LazyAttrTokenStream { } } -impl HashStable for LazyAttrTokenStream { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { +impl HashStable for LazyAttrTokenStream { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { panic!("Attempted to compute stable hash for LazyAttrTokenStream"); } } @@ -824,11 +824,8 @@ impl FromIterator for TokenStream { } } -impl HashStable for TokenStream -where - Hcx: HashStableContext, -{ - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for TokenStream { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { for sub_tt in self.iter() { sub_tt.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index c74e0b9b1a669..cb65067c7a69a 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -14,7 +14,7 @@ use rustc_codegen_ssa::back::write::produce_final_output_artifacts; use rustc_codegen_ssa::base::determine_cgu_reuse; use rustc_codegen_ssa::{CompiledModule, CompiledModules, ModuleKind}; use rustc_data_structures::profiling::SelfProfilerRef; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; use rustc_hir::attrs::Linkage as RLinkage; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; @@ -45,8 +45,8 @@ enum OngoingModuleCodegen { Async(JoinHandle>), } -impl HashStable for OngoingModuleCodegen { - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { +impl HashStable for OngoingModuleCodegen { + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { // do nothing } } diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index de79acd165f0f..c963bb9de4b42 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -98,12 +98,12 @@ pub enum TypeKind { // for now we content ourselves with providing a no-op HashStable // implementation for CGUs. mod temp_stable_hash_impls { - use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; + use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use crate::ModuleCodegen; - impl HashStable for ModuleCodegen { - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { + impl HashStable for ModuleCodegen { + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { // do nothing } } diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index e196ff0941594..419cdc115518c 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher}; use std::ops::Deref; use std::ptr; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{HashStable, HashStableContext, StableHasher}; mod private { #[derive(Clone, Copy, Debug)] @@ -103,11 +103,11 @@ where } } -impl HashStable for Interned<'_, T> +impl HashStable for Interned<'_, T> where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.0.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/packed.rs b/compiler/rustc_data_structures/src/packed.rs index eef25331987da..30f76cb4476c5 100644 --- a/compiler/rustc_data_structures/src/packed.rs +++ b/compiler/rustc_data_structures/src/packed.rs @@ -3,7 +3,7 @@ use std::fmt; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{HashStable, HashStableContext, StableHasher}; /// A packed 128-bit integer. Useful for reducing the size of structures in /// some cases. @@ -60,9 +60,9 @@ impl fmt::UpperHex for Pu128 { } } -impl HashStable for Pu128 { +impl HashStable for Pu128 { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { { self.0 }.hash_stable(hcx, hasher) } } diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 49c5272bd8568..ca813a36059ba 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -7,7 +7,7 @@ use std::ops::{Bound, Index, IndexMut, RangeBounds}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; -use crate::stable_hasher::{HashStable, StableHasher, StableOrd}; +use crate::stable_hasher::{HashStable, HashStableContext, StableHasher, StableOrd}; mod index_map; @@ -347,9 +347,9 @@ impl FromIterator<(K, V)> for SortedMap { } } -impl + StableOrd, V: HashStable, Hcx> HashStable for SortedMap { +impl HashStable for SortedMap { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.data.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 1ef86768eb504..4468eeeb1b2d8 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -15,7 +15,7 @@ pub use rustc_stable_hash::{ FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher, }; -/// This trait lets `HashStable` and `derive(HashStable_Generic)` be used in +/// This trait lets `HashStable` and `derive(HashStable)` 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. @@ -26,6 +26,9 @@ pub trait HashStableContext { /// Compute a `DefPathHash`. fn def_path_hash(&self, def_id: RawDefId) -> RawDefPathHash; + /// Get the hashing controls. + fn hashing_controls(&self) -> HashingControls; + /// Assert that the provided `HashStableContext` is configured with the default /// `HashingControls`. We should always have bailed out before getting to here with a fn assert_default_hashing_controls(&self, msg: &str); @@ -49,7 +52,7 @@ pub struct RawDefPathHash { _data: u128, } -/// Something that implements `HashStable` can be hashed in a way that is +/// Something that implements `HashStable` can be hashed in a way that is /// stable across multiple compilation sessions. /// /// Note that `HashStable` imposes rather more strict requirements than usual @@ -75,16 +78,16 @@ pub struct RawDefPathHash { /// - `hash_stable()` must be independent of the host architecture. The /// `StableHasher` takes care of endianness and `isize`/`usize` platform /// differences. -pub trait HashStable { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); +pub trait HashStable { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); } /// Implement this for types that can be turned into stable keys like, for /// example, for DefId that can be converted to a DefPathHash. This is used for /// bringing maps into a predictable order before hashing them. -pub trait ToStableHashKey { - type KeyType: Ord + Sized + HashStable; - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType; +pub trait ToStableHashKey { + type KeyType: Ord + Sized + HashStable; + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType; } /// Trait for marking a type as having a sort order that is @@ -167,12 +170,16 @@ impl StableCompare for T { /// for examples). Therefore this macro is not exported and should only be used in the limited cases /// here in this module. /// -/// Use `#[derive(HashStable_Generic)]` instead. +/// Use `#[derive(HashStable)]` instead. macro_rules! impl_stable_traits_for_trivial_type { ($t:ty) => { - impl $crate::stable_hasher::HashStable for $t { + impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut $crate::stable_hasher::StableHasher) { + fn hash_stable( + &self, + _: &mut Hcx, + hasher: &mut $crate::stable_hasher::StableHasher, + ) { ::std::hash::Hash::hash(self, hasher); } } @@ -211,9 +218,9 @@ impl_stable_traits_for_trivial_type!(Hash64); // We need a custom impl as the default hash function will only hash half the bits. For stable // hashing we want to hash the full 128-bit hash. -impl HashStable for Hash128 { +impl HashStable for Hash128 { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { self.as_u128().hash(hasher); } } @@ -226,61 +233,61 @@ impl StableOrd for Hash128 { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for ! { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { +impl HashStable for ! { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { unreachable!() } } -impl HashStable for PhantomData { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {} +impl HashStable for PhantomData { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {} } -impl HashStable for NonZero { +impl HashStable for NonZero { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.get().hash_stable(hcx, hasher) } } -impl HashStable for NonZero { +impl HashStable for NonZero { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.get().hash_stable(hcx, hasher) } } -impl HashStable for f32 { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for f32 { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let val: u32 = self.to_bits(); val.hash_stable(hcx, hasher); } } -impl HashStable for f64 { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for f64 { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let val: u64 = self.to_bits(); val.hash_stable(hcx, hasher); } } -impl HashStable for ::std::cmp::Ordering { +impl HashStable for ::std::cmp::Ordering { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (*self as i8).hash_stable(hcx, hasher); } } -impl, Hcx> HashStable for (T1,) { +impl HashStable for (T1,) { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0,) = *self; _0.hash_stable(hcx, hasher); } } -impl, T2: HashStable, Hcx> HashStable for (T1, T2) { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for (T1, T2) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -295,13 +302,13 @@ impl StableOrd for (T1, T2) { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for (T1, T2, T3) +impl HashStable for (T1, T2, T3) where - T1: HashStable, - T2: HashStable, - T3: HashStable, + T1: HashStable, + T2: HashStable, + T3: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -318,14 +325,14 @@ impl StableOrd for (T1, T2, T3) { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for (T1, T2, T3, T4) +impl HashStable for (T1, T2, T3, T4) where - T1: HashStable, - T2: HashStable, - T3: HashStable, - T4: HashStable, + T1: HashStable, + T2: HashStable, + T3: HashStable, + T4: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -345,8 +352,12 @@ impl StableOrd for ( const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl, Hcx> HashStable for [T] { - default fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for [T] { + default fn hash_stable( + &self, + hcx: &mut Hcx, + hasher: &mut StableHasher, + ) { self.len().hash_stable(hcx, hasher); for item in self { item.hash_stable(hcx, hasher); @@ -354,28 +365,28 @@ impl, Hcx> HashStable for [T] { } } -impl HashStable for [u8] { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for [u8] { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); hasher.write(self); } } -impl, Hcx> HashStable for Vec { +impl HashStable for Vec { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } -impl HashStable for indexmap::IndexMap +impl HashStable for indexmap::IndexMap where - K: HashStable + Eq + Hash, - V: HashStable, + K: HashStable + Eq + Hash, + V: HashStable, R: BuildHasher, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for kv in self { kv.hash_stable(hcx, hasher); @@ -383,13 +394,13 @@ where } } -impl HashStable for indexmap::IndexSet +impl HashStable for indexmap::IndexSet where - K: HashStable + Eq + Hash, + K: HashStable + Eq + Hash, R: BuildHasher, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for key in self { key.hash_stable(hcx, hasher); @@ -397,40 +408,40 @@ where } } -impl HashStable for SmallVec<[A; N]> +impl HashStable for SmallVec<[A; N]> where - A: HashStable, + A: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } -impl, Hcx> HashStable for Box { +impl HashStable for Box { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } -impl, Hcx> HashStable for ::std::rc::Rc { +impl HashStable for ::std::rc::Rc { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } -impl, Hcx> HashStable for ::std::sync::Arc { +impl HashStable for ::std::sync::Arc { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } -impl HashStable for str { +impl HashStable for str { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_bytes().hash_stable(hcx, hasher); } } @@ -443,9 +454,9 @@ impl StableOrd for &str { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for String { +impl HashStable for String { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } @@ -458,25 +469,25 @@ impl StableOrd for String { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl ToStableHashKey for String { +impl ToStableHashKey for String { type KeyType = String; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { self.clone() } } -impl, T2: ToStableHashKey> ToStableHashKey for (T1, T2) { +impl ToStableHashKey for (T1, T2) { type KeyType = (T1::KeyType, T2::KeyType); #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType { (self.0.to_stable_hash_key(hcx), self.1.to_stable_hash_key(hcx)) } } -impl HashStable for bool { +impl HashStable for bool { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (if *self { 1u8 } else { 0u8 }).hash_stable(hcx, hasher); } } @@ -488,12 +499,12 @@ impl StableOrd for bool { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for Option +impl HashStable for Option where - T: HashStable, + T: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { if let Some(ref value) = *self { 1u8.hash_stable(hcx, hasher); value.hash_stable(hcx, hasher); @@ -510,13 +521,13 @@ impl StableOrd for Option { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for Result +impl HashStable for Result where - T1: HashStable, - T2: HashStable, + T1: HashStable, + T2: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { Ok(ref x) => x.hash_stable(hcx, hasher), @@ -525,39 +536,39 @@ where } } -impl<'a, T, Hcx> HashStable for &'a T +impl<'a, T> HashStable for &'a T where - T: HashStable + ?Sized, + T: HashStable + ?Sized, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } -impl HashStable for ::std::mem::Discriminant { +impl HashStable for ::std::mem::Discriminant { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } -impl HashStable for ::std::ops::RangeInclusive +impl HashStable for ::std::ops::RangeInclusive where - T: HashStable, + T: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.start().hash_stable(hcx, hasher); self.end().hash_stable(hcx, hasher); } } -impl HashStable for IndexSlice +impl HashStable for IndexSlice where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for v in &self.raw { v.hash_stable(hcx, hasher); @@ -565,11 +576,11 @@ where } } -impl HashStable for IndexVec +impl HashStable for IndexVec where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for v in &self.raw { v.hash_stable(hcx, hasher); @@ -577,14 +588,14 @@ where } } -impl HashStable for DenseBitSet { - fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for DenseBitSet { + fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } -impl HashStable for bit_set::BitMatrix { - fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for bit_set::BitMatrix { + fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -597,15 +608,15 @@ impl_stable_traits_for_trivial_type!(::std::path::PathBuf); // It is not safe to implement HashStable for HashSet, HashMap or any other collection type // with unstable but observable iteration order. // See https://github.com/rust-lang/compiler-team/issues/533 for further information. -impl !HashStable for std::collections::HashSet {} -impl !HashStable for std::collections::HashMap {} +impl !HashStable for std::collections::HashSet {} +impl !HashStable for std::collections::HashMap {} -impl HashStable for ::std::collections::BTreeMap +impl HashStable for ::std::collections::BTreeMap where - K: HashStable + StableOrd, - V: HashStable, + K: HashStable + StableOrd, + V: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); @@ -613,11 +624,11 @@ where } } -impl HashStable for ::std::collections::BTreeSet +impl HashStable for ::std::collections::BTreeSet where - K: HashStable + StableOrd, + K: HashStable + StableOrd, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); diff --git a/compiler/rustc_data_structures/src/stable_hasher/tests.rs b/compiler/rustc_data_structures/src/stable_hasher/tests.rs index 55a666d2d0fc2..da12d7ed7876b 100644 --- a/compiler/rustc_data_structures/src/stable_hasher/tests.rs +++ b/compiler/rustc_data_structures/src/stable_hasher/tests.rs @@ -7,10 +7,25 @@ use super::*; // ways). The expected values depend on the hashing algorithm used, so they // need to be updated whenever StableHasher changes its hashing algorithm. -fn hash>(t: &T) -> Hash128 { +impl HashStableContext for () { + fn span_hash_stable(&mut self, _: RawSpan, _: &mut StableHasher) { + panic!(); + } + fn def_path_hash(&self, _: RawDefId) -> RawDefPathHash { + panic!(); + } + fn hashing_controls(&self) -> HashingControls { + panic!(); + } + fn assert_default_hashing_controls(&self, _: &str) { + panic!(); + } +} + +fn hash(t: &T) -> Hash128 { let mut h = StableHasher::new(); - let ctx = &mut (); - t.hash_stable(ctx, &mut h); + let hcx = &mut (); + t.hash_stable(hcx, &mut h); h.finish() } @@ -44,8 +59,12 @@ fn test_attribute_permutation() { b: $ty, } - impl HashStable for Foo { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + impl HashStable for Foo { + fn hash_stable( + &self, + hcx: &mut Hcx, + hasher: &mut StableHasher, + ) { self.a.hash_stable(hcx, hasher); self.b.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/steal.rs b/compiler/rustc_data_structures/src/steal.rs index 184acfe8ca1a6..8e55323873951 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -1,4 +1,4 @@ -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{HashStable, HashStableContext, StableHasher}; use crate::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard, RwLock, WriteGuard}; /// The `Steal` struct is intended to used as the value for a query. @@ -71,8 +71,8 @@ impl Steal { } } -impl> HashStable for Steal { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for Steal { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.borrow().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index 32f8138110895..d5cc78dd9221d 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -12,7 +12,7 @@ use std::ops::Deref; use std::ptr::NonNull; use crate::aligned::Aligned; -use crate::stable_hasher::{HashStable, StableHasher}; +use crate::stable_hasher::{HashStable, HashStableContext, StableHasher}; /// This describes tags that the [`TaggedRef`] struct can hold. /// @@ -262,12 +262,12 @@ impl Hash for TaggedRef<'_, P, T> { } } -impl<'a, P, T, Hcx> HashStable for TaggedRef<'a, P, T> +impl<'a, P, T> HashStable for TaggedRef<'a, P, T> where - P: HashStable + Aligned + ?Sized, - T: Tag + HashStable, + P: HashStable + Aligned + ?Sized, + T: Tag + HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.pointer().hash_stable(hcx, hasher); self.tag().hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs index e663df5105f95..a1c53ef854326 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs @@ -32,8 +32,12 @@ unsafe impl Tag for Tag2 { } } -impl crate::stable_hasher::HashStable for Tag2 { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::stable_hasher::StableHasher) { +impl HashStable for Tag2 { + fn hash_stable( + &self, + hcx: &mut Hcx, + hasher: &mut crate::stable_hasher::StableHasher, + ) { (*self as u8).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index b0550f0a4f698..4c033065abe3d 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -12,7 +12,9 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; use crate::fingerprint::Fingerprint; use crate::fx::{FxBuildHasher, FxHashMap, FxHashSet}; -use crate::stable_hasher::{HashStable, StableCompare, StableHasher, ToStableHashKey}; +use crate::stable_hasher::{ + HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey, +}; /// `UnordItems` is the order-less version of `Iterator`. It only contains methods /// that don't (easily) expose an ordering of the underlying items. @@ -143,9 +145,9 @@ impl<'a, T: Copy + 'a, I: Iterator> UnordItems<&'a T, I> { impl> UnordItems { #[inline] - pub fn into_sorted(self, hcx: &mut Hcx) -> Vec + pub fn into_sorted(self, hcx: &mut Hcx) -> Vec where - T: ToStableHashKey, + T: ToStableHashKey, { self.collect_sorted(hcx, true) } @@ -170,7 +172,8 @@ impl> UnordItems { #[inline] pub fn collect_sorted(self, hcx: &mut Hcx, cache_sort_key: bool) -> C where - T: ToStableHashKey, + Hcx: HashStableContext, + T: ToStableHashKey, C: FromIterator + BorrowMut<[T]>, { let mut items: C = self.0.collect(); @@ -317,7 +320,8 @@ impl UnordSet { #[inline] pub fn to_sorted(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<&V> where - V: ToStableHashKey, + Hcx: HashStableContext, + V: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&x| x) } @@ -359,7 +363,8 @@ impl UnordSet { #[inline] pub fn into_sorted(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec where - V: ToStableHashKey, + Hcx: HashStableContext, + V: ToStableHashKey, { to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |x| x) } @@ -415,9 +420,9 @@ impl> From> for UnordSet } } -impl> HashStable for UnordSet { +impl HashStable for UnordSet { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -557,7 +562,8 @@ impl UnordMap { #[inline] pub fn to_sorted(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(&K, &V)> where - K: ToStableHashKey, + Hcx: HashStableContext, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k) } @@ -584,7 +590,8 @@ impl UnordMap { #[inline] pub fn into_sorted(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(K, V)> where - K: ToStableHashKey, + Hcx: HashStableContext, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |(k, _)| k) } @@ -616,7 +623,8 @@ impl UnordMap { cache_sort_key: bool, ) -> impl Iterator where - K: ToStableHashKey, + Hcx: HashStableContext, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k) .into_iter() @@ -642,9 +650,9 @@ where } } -impl, V: HashStable> HashStable for UnordMap { +impl HashStable for UnordMap { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -705,9 +713,9 @@ impl> From> for UnordBag { } } -impl> HashStable for UnordBag { +impl HashStable for UnordBag { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -720,8 +728,9 @@ fn to_sorted_vec( extract_key: fn(&T) -> &K, ) -> Vec where + Hcx: HashStableContext, I: Iterator, - K: ToStableHashKey, + K: ToStableHashKey, { let mut items: Vec = iter.collect(); if cache_sort_key { @@ -734,8 +743,8 @@ where } fn hash_iter_order_independent< - Hcx, - T: HashStable, + Hcx: HashStableContext, + T: HashStable, I: Iterator + ExactSizeIterator, >( mut it: I, diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 859a1ad391cb9..3aa494a752b8a 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -5,6 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use rustc_data_structures::AtomicRef; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_span::{Span, Symbol, sym}; use super::{Feature, to_nonzero}; @@ -119,6 +120,32 @@ impl Features { } } +impl HashStable for Features { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + // Unfortunately we cannot exhaustively list fields here, since the + // struct has private fields (to ensure its invariant is maintained) + self.enabled_lang_features().hash_stable(hcx, hasher); + self.enabled_lib_features().hash_stable(hcx, hasher); + } +} + +impl HashStable for EnabledLangFeature { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + let EnabledLangFeature { gate_name, attr_sp, stable_since } = self; + gate_name.hash_stable(hcx, hasher); + attr_sp.hash_stable(hcx, hasher); + stable_since.hash_stable(hcx, hasher); + } +} + +impl HashStable for EnabledLibFeature { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + let EnabledLibFeature { gate_name, attr_sp } = self; + gate_name.hash_stable(hcx, hasher); + attr_sp.hash_stable(hcx, hasher); + } +} + macro_rules! declare_features { ($( $(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr), diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 0cf8a67727840..608835dfbe917 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use rustc_ast as ast; use rustc_ast::NodeId; -use rustc_data_structures::stable_hasher::{HashStableContext, ToStableHashKey}; +use rustc_data_structures::stable_hasher::ToStableHashKey; use rustc_data_structures::unord::UnordMap; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; @@ -712,11 +712,11 @@ impl IntoDiagArg for Namespace { } } -impl ToStableHashKey for Namespace { +impl ToStableHashKey for Namespace { type KeyType = Namespace; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> Namespace { + fn to_stable_hash_key(&self, _: &mut Hcx) -> Namespace { *self } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 71ef6c9a9c03c..2ccf9a532b9b3 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1250,7 +1250,7 @@ pub struct AttrItem { pub span: Span, } -/// The derived implementation of [`HashStable_Generic`] on [`Attribute`]s shouldn't hash +/// The derived implementation of [`HashStable`] on [`Attribute`]s shouldn't hash /// [`AttrId`]s. By wrapping them in this, we make sure we never do. #[derive(Copy, Debug, Encodable, Decodable, Clone)] pub struct HashIgnoredAttrId { diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index c144f0b7dbc5b..8efc85a5af42e 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -8,7 +8,7 @@ //! * Functions called by the compiler itself. use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_macros::{BlobDecodable, Encodable, HashStable_Generic, PrintAttribute}; use rustc_span::{Symbol, kw, sym}; @@ -144,8 +144,8 @@ macro_rules! language_item_table { } } -impl HashStable for LangItem { - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for LangItem { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index 5cccbb821bfbf..e713147724652 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -10,48 +10,51 @@ use crate::hir::{ use crate::hir_id::ItemLocalId; use crate::lints::DelayedLints; -impl ToStableHashKey for BodyId { +impl ToStableHashKey for BodyId { type KeyType = (DefPathHash, ItemLocalId); #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) { + fn to_stable_hash_key( + &self, + hcx: &mut Hcx, + ) -> (DefPathHash, ItemLocalId) { let BodyId { hir_id } = *self; hir_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ItemId { +impl ToStableHashKey for ItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for TraitItemId { +impl ToStableHashKey for TraitItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ImplItemId { +impl ToStableHashKey for ImplItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ForeignItemId { +impl ToStableHashKey for ForeignItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } @@ -63,8 +66,8 @@ impl ToStableHashKey for ForeignItemId { // want to pick up on a reference changing its target, so we hash the NodeIds // in "DefPath Mode". -impl<'tcx, Hcx: HashStableContext> HashStable for OwnerNodes<'tcx> { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl<'tcx> HashStable 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 @@ -75,15 +78,15 @@ impl<'tcx, Hcx: HashStableContext> HashStable for OwnerNodes<'tcx> { } } -impl HashStable for DelayedLints { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable 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, Hcx: HashStableContext> HashStable for AttributeMap<'tcx> { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl<'tcx> HashStable 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; @@ -91,8 +94,8 @@ impl<'tcx, Hcx: HashStableContext> HashStable for AttributeMap<'tcx> { } } -impl HashStable for HashIgnoredAttrId { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { +impl HashStable for HashIgnoredAttrId { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { /* we don't hash HashIgnoredAttrId, we ignore them */ } } diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs index 2f44aba439f4d..7443b9955db29 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -55,18 +55,18 @@ impl rustc_index::Idx for OwnerId { } } -impl HashStable for OwnerId { +impl HashStable for OwnerId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } -impl ToStableHashKey for OwnerId { +impl ToStableHashKey for OwnerId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.to_def_id().to_stable_hash_key(hcx) } } @@ -152,7 +152,7 @@ rustc_index::newtype_index! { /// integers starting at zero, so a mapping that maps all or most nodes within /// an "item-like" to something else can be implemented by a `Vec` instead of a /// tree or hash map. - #[stable_hash_generic] + #[stable_hash] #[encodable] #[orderable] pub struct ItemLocalId {} @@ -177,21 +177,24 @@ pub const CRATE_HIR_ID: HirId = pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID }; -impl ToStableHashKey for HirId { +impl ToStableHashKey for HirId { type KeyType = (DefPathHash, ItemLocalId); #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) { + fn to_stable_hash_key( + &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 { +impl ToStableHashKey for ItemLocalId { type KeyType = ItemLocalId; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId { + fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId { *self } } diff --git a/compiler/rustc_index_macros/src/newtype.rs b/compiler/rustc_index_macros/src/newtype.rs index b6ee283e736c4..2d77df9948ce5 100644 --- a/compiler/rustc_index_macros/src/newtype.rs +++ b/compiler/rustc_index_macros/src/newtype.rs @@ -24,8 +24,6 @@ impl Parse for Newtype { let mut encodable = false; let mut ord = false; let mut stable_hash = false; - let mut stable_hash_generic = false; - let mut stable_hash_no_context = false; let mut gate_rustc_only = quote! {}; let mut gate_rustc_only_cfg = quote! { all() }; @@ -48,14 +46,6 @@ impl Parse for Newtype { stable_hash = true; false } - "stable_hash_generic" => { - stable_hash_generic = true; - false - } - "stable_hash_no_context" => { - stable_hash_no_context = true; - false - } "max" => { let Meta::NameValue(MetaNameValue { value: Expr::Lit(lit), .. }) = &attr.meta else { @@ -165,17 +155,14 @@ impl Parse for Newtype { let hash_stable = if stable_hash { quote! { #gate_rustc_only - impl<'__ctx> ::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>> for #name { - fn hash_stable(&self, hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { - self.as_u32().hash_stable(hcx, hasher) - } - } - } - } else if stable_hash_generic || stable_hash_no_context { - quote! { - #gate_rustc_only - impl ::rustc_data_structures::stable_hasher::HashStable for #name { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + impl ::rustc_data_structures::stable_hasher::HashStable for #name { + fn hash_stable< + __Hcx: ::rustc_data_structures::stable_hasher::HashStableContext + >( + &self, + hcx: &mut __Hcx, + hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher + ) { self.as_u32().hash_stable(hcx, hasher) } } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 596e2979c676b..f910748eec668 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -136,9 +136,9 @@ impl LintExpectationId { } } -impl HashStable for LintExpectationId { +impl HashStable for LintExpectationId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { match self { LintExpectationId::Stable { hir_id, attr_index, lint_index, .. } => { hir_id.hash_stable(hcx, hasher); @@ -154,11 +154,11 @@ impl HashStable for LintExpectationId { } } -impl ToStableHashKey for LintExpectationId { +impl ToStableHashKey for LintExpectationId { type KeyType = (DefPathHash, ItemLocalId, u16, u16); #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType { match self { LintExpectationId::Stable { hir_id, attr_index, lint_index, .. } => { let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx); @@ -621,18 +621,18 @@ impl LintId { } } -impl HashStable for LintId { +impl HashStable for LintId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.lint_name_raw().hash_stable(hcx, hasher); } } -impl ToStableHashKey for LintId { +impl ToStableHashKey for LintId { type KeyType = &'static str; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> &'static str { + fn to_stable_hash_key(&self, _: &mut Hcx) -> &'static str { self.lint_name_raw() } } diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index 709f5ccc2a2ad..4fd5c00c411e3 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -1,6 +1,5 @@ use proc_macro2::Ident; use quote::quote; -use syn::parse_quote; struct Attributes { ignore: bool, @@ -42,12 +41,6 @@ pub(crate) fn hash_stable_derive(s: synstructure::Structure<'_>) -> proc_macro2: hash_stable_derive_with_mode(s, HashStableMode::Normal) } -pub(crate) fn hash_stable_generic_derive( - s: synstructure::Structure<'_>, -) -> proc_macro2::TokenStream { - hash_stable_derive_with_mode(s, HashStableMode::Generic) -} - pub(crate) fn hash_stable_no_context_derive( s: synstructure::Structure<'_>, ) -> proc_macro2::TokenStream { @@ -55,13 +48,19 @@ pub(crate) fn hash_stable_no_context_derive( } enum HashStableMode { - // Use the query-system aware stable hashing context. + // Do a normal derive, where any generic type parameter gets a `HashStable` bound. + // For example, in `struct Abc(T, U)` the added bounds are `T: HashStable` and + // `U: HashStable`. Normal, - // Emit a generic implementation that uses a crate-local `StableHashingContext` - // trait, when the crate is upstream of `rustc_middle`. - Generic, - // Emit a hash-stable implementation that takes no context, - // and emits per-field where clauses for (almost-)perfect derives. + + // Do an (almost-)perfect derive, where any field with a generic type parameter gets a + // `HashStable` bound. For example, in `struct Def(T, U::Assoc)` the added bounds are + // `T::HashStable` and `U::Assoc: HashStable` (not `U: HashStable`). + // + // This is used most commonly in `rustc_type_ir` for types like `TyKind`. + // `Interner` does not impl `HashStable`, but the fields of `TyKind` do not use `I` itself, + // instead only using associated types from `I` such as `I::Region`. On types like `TyKind` we + // typically also see the use of `derive_where` for built-in traits such as `Debug`. NoContext, } @@ -69,52 +68,25 @@ fn hash_stable_derive_with_mode( mut s: synstructure::Structure<'_>, mode: HashStableMode, ) -> proc_macro2::TokenStream { - let generic: syn::GenericParam = match mode { - HashStableMode::Normal => parse_quote!('__ctx), - HashStableMode::Generic | HashStableMode::NoContext => parse_quote!(__CTX), - }; - - // no_context impl is able to derive by-field, which is closer to a perfect derive. - s.add_bounds(match mode { - HashStableMode::Normal | HashStableMode::Generic => synstructure::AddBounds::Generics, + let add_bounds = match mode { + HashStableMode::Normal => synstructure::AddBounds::Generics, HashStableMode::NoContext => synstructure::AddBounds::Fields, - }); - - // For generic impl, add `where __CTX: HashStableContext`. - match mode { - HashStableMode::Normal => {} - HashStableMode::Generic => { - s.add_where_predicate(parse_quote! { - __CTX: ::rustc_data_structures::stable_hasher::HashStableContext - }); - } - HashStableMode::NoContext => {} - } + }; - s.add_impl_generic(generic); + s.add_bounds(add_bounds); let discriminant = hash_stable_discriminant(&mut s); let body = hash_stable_body(&mut s); - let context: syn::Type = match mode { - HashStableMode::Normal => { - parse_quote!(::rustc_middle::ich::StableHashingContext<'__ctx>) - } - HashStableMode::Generic | HashStableMode::NoContext => parse_quote!(__CTX), - }; - s.bound_impl( - quote!( - ::rustc_data_structures::stable_hasher::HashStable< - #context - > - ), + quote!(::rustc_data_structures::stable_hasher::HashStable), quote! { #[inline] - fn hash_stable( + fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>( &self, - __hcx: &mut #context, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + __hcx: &mut __Hcx, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher + ) { #discriminant match *self { #body } } diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 44969908b3f41..5e87305258aed 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -58,17 +58,15 @@ pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream { extension::extension(attr, input) } -decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); decl_derive!( - [HashStable_Generic, attributes(stable_hasher)] => - hash_stable::hash_stable_generic_derive + [HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive ); decl_derive!( - [HashStable_NoContext, attributes(stable_hasher)] => - /// `HashStable` implementation that has no `HashStableContext` bound and - /// which adds `where` bounds for `HashStable` based off of fields and not - /// generics. This is suitable for use in crates like `rustc_type_ir`. - hash_stable::hash_stable_no_context_derive + // FIXME: synonym of `HashStable`, will be removed shortly + [HashStable_Generic, attributes(stable_hasher)] => hash_stable::hash_stable_derive +); +decl_derive!( + [HashStable_NoContext, attributes(stable_hasher)] => hash_stable::hash_stable_no_context_derive ); // Encoding and Decoding derives diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 16cb556c5a323..b10425a9e71db 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -231,10 +231,10 @@ impl WorkProductId { WorkProductId { hash: hasher.finish() } } } -impl ToStableHashKey for WorkProductId { +impl ToStableHashKey for WorkProductId { type KeyType = Fingerprint; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { self.hash } } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node_key.rs b/compiler/rustc_middle/src/dep_graph/dep_node_key.rs index 8286ced133913..f81888a816e79 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node_key.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node_key.rs @@ -7,7 +7,6 @@ use rustc_hir::definitions::DefPathHash; use rustc_hir::{HirId, ItemLocalId, OwnerId}; use crate::dep_graph::{DepNode, KeyFingerprintStyle}; -use crate::ich::StableHashingContext; use crate::ty::TyCtxt; /// Trait for query keys as seen by dependency-node tracking. @@ -30,7 +29,7 @@ pub trait DepNodeKey<'tcx>: Debug + Sized { // Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere. impl<'tcx, T> DepNodeKey<'tcx> for T where - T: for<'a> HashStable> + Debug, + T: HashStable + Debug, { #[inline(always)] default fn key_fingerprint_style() -> KeyFingerprintStyle { diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index abd37f2488009..7dea17faa02b8 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -123,7 +123,7 @@ pub struct DepGraphData { pub fn hash_result(hcx: &mut StableHashingContext<'_>, result: &R) -> Fingerprint where - R: for<'a> HashStable>, + R: HashStable, { let mut stable_hasher = StableHasher::new(); result.hash_stable(hcx, &mut stable_hasher); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 8fe65ea5ad12c..ccc3cab85d97e 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -77,8 +77,8 @@ impl<'hir> Crate<'hir> { } } -impl HashStable for Crate<'_> { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable 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) } diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index af4bef46c1cc2..f9527fa6e79de 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -190,4 +190,9 @@ impl<'a> HashStableContext for StableHashingContext<'a> { "Attempted hashing of {msg} with non-default HashingControls: {hashing_controls:?}" ); } + + #[inline] + fn hashing_controls(&self) -> HashingControls { + self.hashing_controls + } } diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs deleted file mode 100644 index d932bfdee6ef6..0000000000000 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ /dev/null @@ -1,81 +0,0 @@ -//! This module contains `HashStable` implementations for various data types -//! from various crates in no particular order. - -use rustc_ast as ast; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_hir as hir; -use rustc_span::{Symbol, sym}; -use smallvec::SmallVec; - -use super::StableHashingContext; - -impl<'a> HashStable> for ast::NodeId { - #[inline] - fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { - panic!("Node IDs should not appear in incremental state"); - } -} - -impl<'a> HashStable> for [hir::Attribute] { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - if self.is_empty() { - self.len().hash_stable(hcx, hasher); - return; - } - - // Some attributes are always ignored during hashing. - let filtered: SmallVec<[&hir::Attribute; 8]> = self - .iter() - .filter(|attr| { - attr.is_doc_comment().is_none() - // FIXME(jdonszelmann) have a better way to handle ignored attrs - && !attr.name().is_some_and(|ident| is_ignored_attr(ident)) - }) - .collect(); - - filtered.len().hash_stable(hcx, hasher); - for attr in filtered { - attr.hash_stable(hcx, hasher); - } - } -} - -#[inline] -fn is_ignored_attr(name: Symbol) -> bool { - const IGNORED_ATTRIBUTES: &[Symbol] = &[ - sym::cfg_trace, // FIXME(#138844) should this really be ignored? - sym::rustc_if_this_changed, - sym::rustc_then_this_would_need, - sym::rustc_clean, - sym::rustc_partition_reused, - sym::rustc_partition_codegened, - sym::rustc_expected_cgu_reuse, - ]; - IGNORED_ATTRIBUTES.contains(&name) -} - -impl<'tcx> HashStable> for rustc_feature::Features { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { - // Unfortunately we cannot exhaustively list fields here, since the - // struct has private fields (to ensure its invariant is maintained) - self.enabled_lang_features().hash_stable(hcx, hasher); - self.enabled_lib_features().hash_stable(hcx, hasher); - } -} - -impl<'tcx> HashStable> for rustc_feature::EnabledLangFeature { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { - let rustc_feature::EnabledLangFeature { gate_name, attr_sp, stable_since } = self; - gate_name.hash_stable(hcx, hasher); - attr_sp.hash_stable(hcx, hasher); - stable_since.hash_stable(hcx, hasher); - } -} - -impl<'tcx> HashStable> for rustc_feature::EnabledLibFeature { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { - let rustc_feature::EnabledLibFeature { gate_name, attr_sp } = self; - gate_name.hash_stable(hcx, hasher); - attr_sp.hash_stable(hcx, hasher); - } -} diff --git a/compiler/rustc_middle/src/ich/mod.rs b/compiler/rustc_middle/src/ich/mod.rs index 99575299c9781..b060bde1f41fe 100644 --- a/compiler/rustc_middle/src/ich/mod.rs +++ b/compiler/rustc_middle/src/ich/mod.rs @@ -3,4 +3,3 @@ pub use self::hcx::StableHashingContext; mod hcx; -mod impls_syntax; diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 0be4c8243d632..96d02ec8041e9 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -5,12 +5,11 @@ use std::hash::Hash; use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_hir::def::DefKind; use rustc_macros::HashStable; use rustc_span::def_id::{CRATE_DEF_ID, LocalDefId}; -use crate::ich::StableHashingContext; use crate::ty::{TyCtxt, Visibility}; /// Represents the levels of effective visibility an item can have. @@ -273,8 +272,8 @@ impl Default for EffectiveVisibilities { } } -impl<'a> HashStable> for EffectiveVisibilities { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl HashStable for EffectiveVisibilities { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let EffectiveVisibilities { ref map } = *self; map.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index 1d394525c0f73..96d4f3140da8c 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, OnceLock}; use rustc_data_structures::graph; use rustc_data_structures::graph::dominators::{Dominators, dominators}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_index::{IndexSlice, IndexVec}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -171,7 +171,7 @@ impl Decodable for Cache { } } -impl HashStable for Cache { +impl HashStable for Cache { #[inline] - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {} + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {} } diff --git a/compiler/rustc_middle/src/mono.rs b/compiler/rustc_middle/src/mono.rs index 3909db8bfce6e..90ddc1cba6555 100644 --- a/compiler/rustc_middle/src/mono.rs +++ b/compiler/rustc_middle/src/mono.rs @@ -5,7 +5,9 @@ use std::hash::Hash; use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, ToStableHashKey, +}; use rustc_data_structures::unord::UnordMap; use rustc_hashes::Hash128; use rustc_hir::ItemId; @@ -19,7 +21,6 @@ use tracing::debug; use crate::dep_graph::dep_node::{make_compile_codegen_unit, make_compile_mono_item}; use crate::dep_graph::{DepNode, WorkProduct, WorkProductId}; -use crate::ich::StableHashingContext; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::ty::{self, GenericArgs, Instance, InstanceKind, SymbolName, Ty, TyCtxt}; @@ -325,10 +326,10 @@ impl<'tcx> fmt::Display for MonoItem<'tcx> { } } -impl ToStableHashKey> for MonoItem<'_> { +impl ToStableHashKey for MonoItem<'_> { type KeyType = Fingerprint; - fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'_>) -> Self::KeyType { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType { let mut hasher = StableHasher::new(); self.hash_stable(hcx, &mut hasher); hasher.finish() @@ -581,10 +582,10 @@ impl<'tcx> CodegenUnit<'tcx> { } } -impl ToStableHashKey> for CodegenUnit<'_> { +impl ToStableHashKey for CodegenUnit<'_> { type KeyType = String; - fn to_stable_hash_key(&self, _: &mut StableHashingContext<'_>) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { // Codegen unit names are conceptually required to be stable across // compilation session so that object file names match up. self.name.to_string() diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index ad101cf34da3b..a20d92f027c1f 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -11,7 +11,6 @@ use rustc_hir::hir_id::OwnerId; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; use crate::dep_graph::DepNodeIndex; -use crate::ich::StableHashingContext; use crate::infer::canonical::CanonicalQueryInput; use crate::mono::CollectionMode; use crate::query::{DefIdCache, DefaultCache, SingleCache, VecCache}; @@ -24,7 +23,7 @@ use crate::{mir, traits}; #[derive(Copy, Clone, Debug)] pub struct LocalCrate; -pub trait QueryKeyBounds = Copy + Debug + Eq + Hash + for<'a> HashStable>; +pub trait QueryKeyBounds = Copy + Debug + Eq + Hash + HashStable; /// Controls what types can legally be used as the key for a query. pub trait QueryKey: Sized + QueryKeyBounds { diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index ae3c45877900b..0e46a0007ecf7 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -7,7 +7,9 @@ use rustc_abi::{FIRST_VARIANT, FieldIdx, ReprOptions, VariantIdx}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::intern::Interned; -use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, HashingControls, StableHasher, +}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -23,7 +25,6 @@ use tracing::{debug, info, trace}; use super::{ AsyncDestructor, Destructor, FieldDef, GenericPredicates, Ty, TyCtxt, VariantDef, VariantDiscr, }; -use crate::ich::StableHashingContext; use crate::mir::interpret::ErrorHandled; use crate::ty::util::{Discr, IntTypeExt}; use crate::ty::{self, ConstKind}; @@ -151,8 +152,8 @@ impl Hash for AdtDefData { } } -impl<'a> HashStable> for AdtDefData { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl HashStable for AdtDefData { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { thread_local! { static CACHE: RefCell> = Default::default(); } diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 25ad8a5e0820d..61c0575755bec 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -4,6 +4,7 @@ use std::num::NonZero; use rustc_abi::Size; use rustc_apfloat::Float; use rustc_apfloat::ieee::{Double, Half, Quad, Single}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use crate::ty::TyCtxt; @@ -151,8 +152,12 @@ pub struct ScalarInt { // Cannot derive these, as the derives take references to the fields, and we // can't take references to fields of packed structs. -impl crate::ty::HashStable for ScalarInt { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::ty::StableHasher) { +impl HashStable for ScalarInt { + fn hash_stable( + &self, + hcx: &mut Hcx, + hasher: &mut crate::ty::StableHasher, + ) { // Using a block `{self.data}` here to force a copy instead of using `self.data` // directly, because `hash_stable` takes `&self` and would thus borrow `self.data`. // Since `Self` is a packed struct, that would create a possibly unaligned reference, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index f0707cfbbb40c..25682001d0824 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -251,7 +251,7 @@ impl<'tcx> CtxtInterners<'tcx> { )) } - fn stable_hash<'a, T: HashStable>>( + fn stable_hash<'a, T: HashStable>( &self, flags: &ty::FlagComputation>, sess: &'a Session, @@ -607,7 +607,7 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> { /// Never return a `Feed` from a query. Only queries that create a `DefId` are /// allowed to feed queries for that `DefId`. -impl !HashStable for TyCtxtFeed<'_, KEY> {} +impl !HashStable for TyCtxtFeed<'_, KEY> {} /// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`. /// Use this to pass around when you have a `TyCtxt` elsewhere. @@ -622,7 +622,7 @@ pub struct Feed<'tcx, KEY: Copy> { /// Never return a `Feed` from a query. Only queries that create a `DefId` are /// allowed to feed queries for that `DefId`. -impl !HashStable for Feed<'_, KEY> {} +impl !HashStable for Feed<'_, KEY> {} impl fmt::Debug for Feed<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index 883739e193477..c3777cf592cac 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -7,19 +7,18 @@ use std::ptr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{ - HashStable, HashingControls, StableHasher, ToStableHashKey, + HashStable, HashStableContext, HashingControls, StableHasher, ToStableHashKey, }; use tracing::trace; -use crate::ich::StableHashingContext; use crate::middle::region; use crate::{mir, ty}; -impl<'a, 'tcx, H, T> HashStable> for &'tcx ty::list::RawList +impl<'tcx, H, T> HashStable for &'tcx ty::list::RawList where - T: HashStable>, + T: HashStable, { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { // Note: this cache makes an *enormous* performance difference on certain benchmarks. E.g. // without it, compiling `diesel-2.2.10` can be 74% slower, and compiling // `deeply-nested-multi` can be ~4,000x slower(!) @@ -46,29 +45,29 @@ where } } -impl<'a, 'tcx, H, T> ToStableHashKey> for &'tcx ty::list::RawList +impl<'tcx, H, T> ToStableHashKey for &'tcx ty::list::RawList where - T: HashStable>, + T: HashStable, { type KeyType = Fingerprint; #[inline] - fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'a>) -> Fingerprint { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Fingerprint { let mut hasher = StableHasher::new(); self.hash_stable(hcx, &mut hasher); hasher.finish() } } -impl<'a, 'tcx> HashStable> for ty::GenericArg<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl<'tcx> HashStable for ty::GenericArg<'tcx> { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.kind().hash_stable(hcx, hasher); } } // AllocIds get resolved to whatever they point to (to be stable) -impl<'a> HashStable> for mir::interpret::AllocId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl HashStable for mir::interpret::AllocId { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { ty::tls::with_opt(|tcx| { trace!("hashing {:?}", *self); let tcx = tcx.expect("can't hash AllocIds during hir lowering"); @@ -77,17 +76,17 @@ impl<'a> HashStable> for mir::interpret::AllocId { } } -impl<'a> HashStable> for mir::interpret::CtfeProvenance { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl HashStable for mir::interpret::CtfeProvenance { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.into_parts().hash_stable(hcx, hasher); } } -impl<'a> ToStableHashKey> for region::Scope { +impl ToStableHashKey for region::Scope { type KeyType = region::Scope; #[inline] - fn to_stable_hash_key(&self, _: &mut StableHashingContext<'a>) -> region::Scope { + fn to_stable_hash_key(&self, _: &mut Hcx) -> region::Scope { *self } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 36a474688f07a..5369e5d8fbe0d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -32,7 +32,7 @@ use rustc_ast::node_id::NodeMap; pub use rustc_ast_ir::{Movability, Mutability, try_visit}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer}; @@ -113,7 +113,6 @@ pub use self::typeck_results::{ Rust2024IncompatiblePatInfo, TypeckResults, UserType, UserTypeAnnotationIndex, UserTypeKind, }; use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason}; -use crate::ich::StableHashingContext; use crate::metadata::{AmbigModChild, ModChild}; use crate::middle::privacy::EffectiveVisibilities; use crate::mir::{Body, CoroutineLayout, CoroutineSavedLocal, SourceInfo}; @@ -511,8 +510,8 @@ impl<'tcx> From> for Term<'tcx> { } } -impl<'a, 'tcx> HashStable> for Term<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl<'tcx> HashStable for Term<'tcx> { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.kind().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 7aafe657ffa1f..72e2f3b6d2f29 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -14,9 +14,7 @@ use std::{cmp, fs, iter}; use externs::{ExternOpt, split_extern_opt}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; -use rustc_data_structures::stable_hasher::{ - HashStableContext, StableHasher, StableOrd, ToStableHashKey, -}; +use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey}; use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::{ColorConfig, DiagCtxtFlags}; use rustc_feature::UnstableFeatures; @@ -638,10 +636,10 @@ macro_rules! define_output_types { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } - impl ToStableHashKey for OutputType { + impl ToStableHashKey for OutputType { type KeyType = Self; - fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType { *self } } diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index bf50fa2889cf0..07a65724eb6a6 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -431,59 +431,59 @@ rustc_data_structures::define_id_collections!( LocalDefId ); -impl HashStable for DefId { +impl HashStable for DefId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } -impl HashStable for LocalDefId { +impl HashStable for LocalDefId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_stable_hash_key(hcx).local_hash().hash_stable(hcx, hasher); } } -impl HashStable for CrateNum { +impl HashStable for CrateNum { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_def_id().to_stable_hash_key(hcx).stable_crate_id().hash_stable(hcx, hasher); } } -impl ToStableHashKey for DefId { +impl ToStableHashKey for DefId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { DefPathHash::from_raw_def_path_hash(hcx.def_path_hash(self.to_raw_def_id())) } } -impl ToStableHashKey for LocalDefId { +impl ToStableHashKey for LocalDefId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.to_def_id().to_stable_hash_key(hcx) } } -impl ToStableHashKey for CrateNum { +impl ToStableHashKey for CrateNum { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { self.as_def_id().to_stable_hash_key(hcx) } } -impl ToStableHashKey for DefPathHash { +impl ToStableHashKey for DefPathHash { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> DefPathHash { + fn to_stable_hash_key(&self, _: &mut Hcx) -> DefPathHash { *self } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index c59643eeacadc..12abfa3a64cf1 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -1519,8 +1519,8 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContex ExpnHash::new(LOCAL_CRATE.as_def_id().to_stable_hash_key(&mut hcx).stable_crate_id(), expn_hash) } -impl HashStable for SyntaxContext { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for SyntaxContext { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { const TAG_EXPANSION: u8 = 0; const TAG_NO_EXPANSION: u8 = 1; @@ -1535,8 +1535,8 @@ impl HashStable for SyntaxContext { } } -impl HashStable for ExpnId { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for ExpnId { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hcx.assert_default_hashing_controls("ExpnId"); let hash = if *self == ExpnId::root() { // Avoid fetching TLS storage for a trivial often-used value. @@ -1549,8 +1549,8 @@ impl HashStable for ExpnId { } } -impl HashStable for LocalExpnId { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for LocalExpnId { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_expn_id().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index daa9b54ba7c8e..aad48a3279918 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2797,11 +2797,8 @@ impl InnerSpan { } } -impl HashStable for Span -where - Hcx: HashStableContext, -{ - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for Span { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { // `span_hash_stable` does all the work. hcx.span_hash_stable(self.to_raw_span(), hasher) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 33bc5a578e8b6..ae4fa6633c806 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -8,7 +8,7 @@ use std::{fmt, str}; use rustc_arena::DroplessArena; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::stable_hasher::{ - HashStable, StableCompare, StableHasher, ToStableHashKey, + HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey, }; use rustc_data_structures::sync::Lock; use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols}; @@ -2612,17 +2612,17 @@ impl fmt::Display for Symbol { } } -impl HashStable for Symbol { +impl HashStable for Symbol { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_str().hash_stable(hcx, hasher); } } -impl ToStableHashKey for Symbol { +impl ToStableHashKey for Symbol { type KeyType = String; #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> String { + fn to_stable_hash_key(&self, _: &mut Hcx) -> String { self.as_str().to_string() } } @@ -2672,9 +2672,9 @@ impl fmt::Debug for ByteSymbol { } } -impl HashStable for ByteSymbol { +impl HashStable for ByteSymbol { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_byte_str().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 2877364762f46..c1ecb8026c54e 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -2,7 +2,7 @@ use std::fmt; use derive_where::derive_where; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; use rustc_type_ir_macros::{ @@ -117,8 +117,8 @@ impl fmt::Debug for InferConst { } #[cfg(feature = "nightly")] -impl HashStable for InferConst { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for InferConst { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { match self { InferConst::Var(_) => { panic!("const variables should not be hashed: {self:?}") diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index a8a04f18d549e..48f1abb8189e4 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -7,7 +7,9 @@ use rustc_ast_ir::Mutability; #[cfg(feature = "nightly")] use rustc_data_structures::fingerprint::Fingerprint; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{ + HashStable, HashStableContext, StableHasher, ToStableHashKey, +}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; @@ -50,11 +52,11 @@ pub enum SimplifiedType { } #[cfg(feature = "nightly")] -impl> ToStableHashKey for SimplifiedType { +impl ToStableHashKey for SimplifiedType { type KeyType = Fingerprint; #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Fingerprint { + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Fingerprint { let mut hasher = StableHasher::new(); self.hash_stable(hcx, &mut hasher); hasher.finish() diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index a0b444024ca79..dc38977fb872e 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -123,7 +123,7 @@ rustc_index::newtype_index! { /// is the outer fn. /// /// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index - #[stable_hash_no_context] + #[stable_hash] #[encodable] #[orderable] #[debug_format = "DebruijnIndex({})"] @@ -333,7 +333,7 @@ rustc_index::newtype_index! { /// declared, but a type name in a non-zero universe is a placeholder /// type -- an idealized representative of "types in general" that we /// use for checking generic functions. - #[stable_hash_no_context] + #[stable_hash] #[encodable] #[orderable] #[debug_format = "U{}"] @@ -388,7 +388,7 @@ impl Default for UniverseIndex { } rustc_index::newtype_index! { - #[stable_hash_generic] + #[stable_hash] #[encodable] #[orderable] #[debug_format = "{}"] diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index d1076be20bae2..b930fede993a7 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -2,7 +2,7 @@ use std::fmt; use derive_where::derive_where; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext}; use rustc_type_ir_macros::GenericTypeVisitable; @@ -16,7 +16,7 @@ rustc_index::newtype_index! { #[orderable] #[debug_format = "'?{}"] #[gate_rustc_only] - #[stable_hash_no_context] + #[stable_hash] pub struct RegionVid {} } @@ -217,15 +217,15 @@ impl fmt::Debug for RegionKind { #[cfg(feature = "nightly")] // This is not a derived impl because a derive would require `I: HashStable` -impl HashStable for RegionKind +impl HashStable for RegionKind where - I::EarlyParamRegion: HashStable, - I::LateParamRegion: HashStable, - I::DefId: HashStable, - I::Symbol: HashStable, + I::EarlyParamRegion: HashStable, + I::LateParamRegion: HashStable, + I::DefId: HashStable, + I::Symbol: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { std::mem::discriminant(self).hash_stable(hcx, hasher); match self { ReErased | ReStatic | ReError(_) => { diff --git a/compiler/rustc_type_ir/src/ty_info.rs b/compiler/rustc_type_ir/src/ty_info.rs index 5e297a51f0ce7..e9d7046a170ca 100644 --- a/compiler/rustc_type_ir/src/ty_info.rs +++ b/compiler/rustc_type_ir/src/ty_info.rs @@ -5,7 +5,7 @@ use std::ops::Deref; #[cfg(feature = "nightly")] use rustc_data_structures::fingerprint::Fingerprint; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_type_ir_macros::GenericTypeVisitable; use crate::{DebruijnIndex, TypeFlags}; @@ -97,8 +97,8 @@ impl Hash for WithCachedTypeInfo { } #[cfg(feature = "nightly")] -impl, Hcx> HashStable for WithCachedTypeInfo { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for WithCachedTypeInfo { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { // No cached hash available. This can only mean that incremental is disabled. // We don't cache stable hashes in non-incremental mode, because they are used diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 9c57d04159cc8..cdc462a075577 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -4,7 +4,7 @@ use std::ops::Deref; use derive_where::derive_where; use rustc_ast_ir::Mutability; #[cfg(feature = "nightly")] -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; use rustc_type_ir::data_structures::{NoError, UnifyKey, UnifyValue}; @@ -708,8 +708,8 @@ impl UnifyKey for FloatVid { } #[cfg(feature = "nightly")] -impl HashStable for InferTy { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { +impl HashStable for InferTy { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { use InferTy::*; std::mem::discriminant(self).hash_stable(hcx, hasher); match self { From eb70b42c929ae0a21eba41f401693d29de8816ab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 8 Apr 2026 13:40:45 +1000 Subject: [PATCH 4/7] Remove `derive(HashStable_Generic)`. It's now just a synonym for `derive(HashStable)`. --- compiler/rustc_abi/src/callconv/reg.rs | 6 +- compiler/rustc_abi/src/canon_abi.rs | 10 +- compiler/rustc_abi/src/layout/ty.rs | 6 +- compiler/rustc_abi/src/lib.rs | 63 ++-- compiler/rustc_ast/src/ast.rs | 72 ++--- .../rustc_ast/src/attr/data_structures.rs | 4 +- compiler/rustc_ast/src/attr/version.rs | 4 +- compiler/rustc_ast/src/expand/allocator.rs | 4 +- .../rustc_ast/src/expand/autodiff_attrs.rs | 6 +- compiler/rustc_ast/src/expand/mod.rs | 2 +- compiler/rustc_ast/src/expand/typetree.rs | 10 +- compiler/rustc_ast/src/token.rs | 28 +- compiler/rustc_ast/src/tokenstream.rs | 10 +- .../rustc_hir/src/attrs/data_structures.rs | 118 ++++---- compiler/rustc_hir/src/attrs/diagnostic.rs | 24 +- compiler/rustc_hir/src/def.rs | 18 +- compiler/rustc_hir/src/diagnostic_items.rs | 4 +- compiler/rustc_hir/src/hir.rs | 276 +++++++++--------- compiler/rustc_hir/src/lang_items.rs | 4 +- compiler/rustc_hir/src/limit.rs | 4 +- compiler/rustc_hir/src/lints.rs | 6 +- compiler/rustc_hir/src/stability.rs | 16 +- compiler/rustc_hir/src/target.rs | 8 +- compiler/rustc_hir_id/src/lib.rs | 4 +- compiler/rustc_index_macros/src/lib.rs | 3 +- compiler/rustc_lint_defs/src/lib.rs | 18 +- compiler/rustc_macros/src/lib.rs | 4 - compiler/rustc_session/src/config.rs | 16 +- compiler/rustc_session/src/cstore.rs | 22 +- compiler/rustc_session/src/search_paths.rs | 4 +- compiler/rustc_session/src/session.rs | 4 +- compiler/rustc_session/src/utils.rs | 4 +- compiler/rustc_span/src/def_id.rs | 10 +- compiler/rustc_span/src/edition.rs | 4 +- compiler/rustc_span/src/hygiene.rs | 16 +- compiler/rustc_span/src/lib.rs | 28 +- compiler/rustc_span/src/symbol.rs | 4 +- compiler/rustc_target/src/asm/mod.rs | 14 +- compiler/rustc_target/src/callconv/mod.rs | 22 +- compiler/rustc_target/src/spec/mod.rs | 8 +- compiler/rustc_target/src/target_features.rs | 4 +- 41 files changed, 413 insertions(+), 479 deletions(-) diff --git a/compiler/rustc_abi/src/callconv/reg.rs b/compiler/rustc_abi/src/callconv/reg.rs index 66d4dca00726f..d857c6796e524 100644 --- a/compiler/rustc_abi/src/callconv/reg.rs +++ b/compiler/rustc_abi/src/callconv/reg.rs @@ -1,9 +1,9 @@ #[cfg(feature = "nightly")] -use rustc_macros::HashStable_Generic; +use rustc_macros::HashStable; use crate::{Align, HasDataLayout, Size}; -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum RegKind { Integer, @@ -11,7 +11,7 @@ pub enum RegKind { Vector, } -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct Reg { pub kind: RegKind, diff --git a/compiler/rustc_abi/src/canon_abi.rs b/compiler/rustc_abi/src/canon_abi.rs index fd45f0ea0e9ec..fc81a5911edd4 100644 --- a/compiler/rustc_abi/src/canon_abi.rs +++ b/compiler/rustc_abi/src/canon_abi.rs @@ -1,7 +1,7 @@ use std::fmt; #[cfg(feature = "nightly")] -use rustc_macros::HashStable_Generic; +use rustc_macros::HashStable; use crate::ExternAbi; @@ -18,7 +18,7 @@ use crate::ExternAbi; /// rather than picking the "actual" ABI. #[derive(Copy, Clone, Debug)] #[derive(PartialOrd, Ord, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum CanonAbi { // NOTE: the use of nested variants for some ABIs is for many targets they don't matter, // and this pushes the complexity of their reasoning to target-specific code, @@ -111,7 +111,7 @@ impl fmt::Display for CanonAbi { /// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar. #[derive(Copy, Clone, Debug)] #[derive(PartialOrd, Ord, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum InterruptKind { Avr, AvrNonBlocking, @@ -126,7 +126,7 @@ pub enum InterruptKind { /// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now? #[derive(Clone, Copy, Debug)] #[derive(PartialOrd, Ord, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum X86Call { /// "fastcall" has both GNU and Windows variants Fastcall, @@ -141,7 +141,7 @@ pub enum X86Call { /// ABIs defined for 32-bit Arm #[derive(Copy, Clone, Debug)] #[derive(PartialOrd, Ord, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum ArmCall { Aapcs, CCmseNonSecureCall, diff --git a/compiler/rustc_abi/src/layout/ty.rs b/compiler/rustc_abi/src/layout/ty.rs index 7698a40629daf..b394f9f4f86dc 100644 --- a/compiler/rustc_abi/src/layout/ty.rs +++ b/compiler/rustc_abi/src/layout/ty.rs @@ -2,7 +2,7 @@ use std::fmt; use std::ops::Deref; use rustc_data_structures::intern::Interned; -use rustc_macros::HashStable_Generic; +use rustc_macros::HashStable; use crate::layout::{FieldIdx, VariantIdx}; use crate::{ @@ -12,7 +12,7 @@ use crate::{ // Explicitly import `Float` to avoid ambiguity with `Primitive::Float`. -#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] #[rustc_pass_by_value] pub struct Layout<'a>(pub Interned<'a, LayoutData>); @@ -71,7 +71,7 @@ impl<'a> Layout<'a> { /// to that obtained from `layout_of(ty)`, as we need to produce /// layouts for which Rust types do not exist, such as enum variants /// or synthetic fields of enums (i.e., discriminants) and wide pointers. -#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)] pub struct TyAndLayout<'a, Ty> { pub ty: Ty, pub layout: Layout<'a>, diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index f148b776852aa..e10de04394865 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -49,7 +49,7 @@ use rustc_data_structures::stable_hasher::StableOrd; use rustc_hashes::Hash64; use rustc_index::{Idx, IndexSlice, IndexVec}; #[cfg(feature = "nightly")] -use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic}; +use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable}; mod callconv; mod canon_abi; @@ -68,10 +68,7 @@ pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorErro pub use layout::{Layout, TyAbiInterface, TyAndLayout}; #[derive(Clone, Copy, PartialEq, Eq, Default)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub struct ReprFlags(u8); bitflags! { @@ -108,10 +105,7 @@ impl std::fmt::Debug for ReprFlags { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub enum IntegerType { /// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g. /// `Pointer(true)` means `isize`. @@ -131,10 +125,7 @@ impl IntegerType { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub enum ScalableElt { /// `N` in `rustc_scalable_vector(N)` - the element count of the scalable vector ElementCount(u16), @@ -145,10 +136,7 @@ pub enum ScalableElt { /// Represents the repr options provided by the user. #[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub struct ReprOptions { pub int: Option, pub align: Option, @@ -745,10 +733,7 @@ impl FromStr for Endian { /// Size of a type in bytes. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub struct Size { raw: u64, } @@ -973,10 +958,7 @@ impl Step for Size { /// Alignment of a type in bytes (always a power of two). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub struct Align { pow2: u8, } @@ -1109,7 +1091,7 @@ impl Align { /// An example of a rare thing actually affected by preferred alignment is aligning of statics. /// It is of effectively no consequence for layout in structs and on the stack. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct AbiAlign { pub abi: Align, } @@ -1141,10 +1123,7 @@ impl Deref for AbiAlign { /// Integers, also used for enum discriminants. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -#[cfg_attr( - feature = "nightly", - derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic) -)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))] pub enum Integer { I8, I16, @@ -1304,7 +1283,7 @@ impl Integer { /// Floating-point types. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum Float { F16, F32, @@ -1339,7 +1318,7 @@ impl Float { /// Fundamental unit of memory access and layout. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum Primitive { /// The `bool` is the signedness of the `Integer` type. /// @@ -1387,7 +1366,7 @@ impl Primitive { /// /// This is intended specifically to mirror LLVM’s `!range` metadata semantics. #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct WrappingRange { pub start: u128, pub end: u128, @@ -1499,7 +1478,7 @@ impl fmt::Debug for WrappingRange { /// Information about one scalar component of a Rust type. #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum Scalar { Initialized { value: Primitive, @@ -1603,7 +1582,7 @@ impl Scalar { // NOTE: This struct is generic over the FieldIdx for rust-analyzer usage. /// Describes how the fields of a type are located in memory. #[derive(PartialEq, Eq, Hash, Clone, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum FieldsShape { /// Scalar primitives and `!`, which never have fields. Primitive, @@ -1688,7 +1667,7 @@ impl FieldsShape { /// should operate on. Special address spaces have an effect on code generation, /// depending on the target and the address spaces it implements. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct AddressSpace(pub u32); impl AddressSpace { @@ -1698,7 +1677,7 @@ impl AddressSpace { /// How many scalable vectors are in a `BackendRepr::ScalableVector`? #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct NumScalableVectors(pub u8); impl NumScalableVectors { @@ -1729,7 +1708,7 @@ impl NumScalableVectors { /// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector, /// and larger values will usually prefer to be represented as memory. #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum BackendRepr { Scalar(Scalar), ScalarPair(Scalar, Scalar), @@ -1873,7 +1852,7 @@ impl BackendRepr { // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. #[derive(PartialEq, Eq, Hash, Clone, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum Variants { /// A type with no valid variants. Must be uninhabited. Empty, @@ -1900,7 +1879,7 @@ pub enum Variants { // NOTE: This struct is generic over the VariantIdx for rust-analyzer usage. #[derive(PartialEq, Eq, Hash, Clone, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub enum TagEncoding { /// The tag directly stores the discriminant, but possibly with a smaller layout /// (so converting the tag to the discriminant can require sign extension). @@ -1941,7 +1920,7 @@ pub enum TagEncoding { } #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct Niche { pub offset: Size, pub value: Primitive, @@ -2028,7 +2007,7 @@ impl Niche { // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. #[derive(PartialEq, Eq, Hash, Clone)] -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] +#[cfg_attr(feature = "nightly", derive(HashStable))] pub struct LayoutData { /// Says where the fields are located within the layout. pub fields: FieldsShape, diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index d62af54647aa7..a61ed89bd0de6 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -28,7 +28,7 @@ use rustc_data_structures::packed::Pu128; use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::tagged_ptr::Tag; -use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; +use rustc_macros::{Decodable, Encodable, HashStable, Walkable}; pub use rustc_span::AttrId; use rustc_span::{ ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, respan, sym, @@ -52,7 +52,7 @@ use crate::visit::{AssocCtxt, BoundKind, LifetimeCtxt}; /// ``` /// /// `'outer` is a label. -#[derive(Clone, Encodable, Decodable, Copy, HashStable_Generic, Eq, PartialEq, Walkable)] +#[derive(Clone, Encodable, Decodable, Copy, HashStable, Eq, PartialEq, Walkable)] pub struct Label { pub ident: Ident, } @@ -564,7 +564,7 @@ pub struct Crate { /// for most built-in attributes. /// /// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable)] pub struct MetaItem { pub unsafety: Safety, pub path: Path, @@ -573,7 +573,7 @@ pub struct MetaItem { } /// The meta item kind, containing the data after the initial path. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable)] pub enum MetaItemKind { /// Word meta item. /// @@ -594,7 +594,7 @@ pub enum MetaItemKind { /// Values inside meta item lists. /// /// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable)] pub enum MetaItemInner { /// A full MetaItem, for recursive meta items. MetaItem(MetaItem), @@ -792,7 +792,7 @@ pub struct PatField { } #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub enum ByRef { Yes(Pinnedness, Mutability), No, @@ -814,7 +814,7 @@ impl ByRef { /// `.0` is the by-reference mode (`ref`, `ref mut`, or by value), /// `.1` is the mutability of the binding. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub struct BindingMode(pub ByRef, pub Mutability); impl BindingMode { @@ -964,7 +964,7 @@ pub enum PatFieldsRest { /// The kind of borrow in an `AddrOf` expression, /// e.g., `&place` or `&raw const place`. #[derive(Clone, Copy, PartialEq, Eq, Debug)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub enum BorrowKind { /// A normal borrow, `&$expr` or `&mut $expr`. /// The resulting type is either `&'a T` or `&'a mut T` @@ -980,7 +980,7 @@ pub enum BorrowKind { Pin, } -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable, Walkable)] pub enum BinOpKind { /// The `+` operator (addition) Add, @@ -1110,7 +1110,7 @@ impl From for BinOpKind { } } -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable, Walkable)] pub enum AssignOpKind { /// The `+=` operator (addition) AddAssign, @@ -1162,7 +1162,7 @@ pub type AssignOp = Spanned; /// Unary operator. /// /// Note that `&data` is not an operator, it's an `AddrOf` expression. -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable, Walkable)] pub enum UnOp { /// The `*` operator for dereferencing Deref, @@ -1961,7 +1961,7 @@ impl GenBlockKind { /// Whether we're unwrapping or wrapping an unsafe binder #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub enum UnsafeBinderCastKind { // e.g. `&i32` -> `unsafe<'a> &'a i32` Wrap, @@ -1995,7 +1995,7 @@ pub struct QSelf { } /// A capture clause used in closures and `async` blocks. -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable, Walkable)] pub enum CaptureBy { /// `move |x| y + x`. Value { @@ -2090,7 +2090,7 @@ impl AttrArgs { } /// Delimited arguments, as used in `#[attr()/[]/{}]` or `mac!()/[]/{}`. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable, Walkable)] pub struct DelimArgs { pub dspan: DelimSpan, pub delim: Delimiter, // Note: `Delimiter::Invisible` never occurs @@ -2106,7 +2106,7 @@ impl DelimArgs { } /// Represents a macro definition. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable, Walkable)] pub struct MacroDef { pub body: Box, /// `true` if macro was defined with `macro_rules`. @@ -2120,7 +2120,7 @@ pub struct MacroDef { pub eii_declaration: Option, } -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable, Walkable)] pub struct EiiDecl { /// path to the extern item we're targeting pub foreign_item: Path, @@ -2128,7 +2128,7 @@ pub struct EiiDecl { } #[derive(Clone, Encodable, Decodable, Debug, Copy, Hash, Eq, PartialEq)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum StrStyle { /// A regular string, like `"foo"`. Cooked, @@ -2186,7 +2186,7 @@ impl YieldKind { } /// A literal in a meta item. -#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable)] pub struct MetaItemLit { /// The original literal as written in the source code. pub symbol: Symbol, @@ -2223,7 +2223,7 @@ impl StrLit { /// Type of the integer literal based on provided suffix. #[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq)] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub enum LitIntType { /// e.g. `42_i32`. Signed(IntTy), @@ -2235,7 +2235,7 @@ pub enum LitIntType { /// Type of the float literal based on provided suffix. #[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq)] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub enum LitFloatType { /// A float literal with a suffix (`1f32` or `1E10f32`). Suffixed(FloatTy), @@ -2249,7 +2249,7 @@ pub enum LitFloatType { /// deciding the `LitKind`. This means that float literals like `1f32` are /// classified by this type as `Float`. This is different to `token::LitKind` /// which does *not* consider the suffix. -#[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable)] pub enum LitKind { /// A string literal (`"foo"`). The symbol is unescaped, and so may differ /// from the original token's symbol. @@ -2652,7 +2652,7 @@ pub enum TyPatKind { } /// Syntax used to declare a trait object. -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable, Walkable)] #[repr(u8)] pub enum TraitObjectSyntax { // SAFETY: When adding new variants make sure to update the `Tag` impl. @@ -2696,7 +2696,7 @@ pub enum InlineAsmRegOrRegClass { RegClass(Symbol), } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)] pub struct InlineAsmOptions(u16); bitflags::bitflags! { impl InlineAsmOptions: u16 { @@ -2759,7 +2759,7 @@ impl std::fmt::Debug for InlineAsmOptions { } } -#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic, Walkable)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable, Walkable)] pub enum InlineAsmTemplatePiece { String(Cow<'static, str>), Placeholder { operand_idx: usize, modifier: Option, span: Span }, @@ -2862,7 +2862,7 @@ impl InlineAsmOperand { } } -#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable, PartialEq, Eq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable, Walkable, PartialEq, Eq)] pub enum AsmMacro { /// The `asm!` macro Asm, @@ -3060,7 +3060,7 @@ impl FnDecl { } /// Is the trait definition an auto trait? -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable, Walkable)] pub enum IsAuto { Yes, No, @@ -3068,7 +3068,7 @@ pub enum IsAuto { /// Safety of items. #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum Safety { /// `unsafe` an item is explicitly marked as `unsafe`. Unsafe(Span), @@ -3133,7 +3133,7 @@ impl CoroutineKind { } #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum Const { Yes(Span), No, @@ -3141,7 +3141,7 @@ pub enum Const { /// Item defaultness. /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532). -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable, Walkable)] pub enum Defaultness { /// Item is unmarked. Implicitly determined based off of position. /// For impls, this is `final`; for traits, this is `default`. @@ -3155,7 +3155,7 @@ pub enum Defaultness { Final(Span), } -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable, Walkable)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -3174,7 +3174,7 @@ impl fmt::Debug for ImplPolarity { /// The polarity of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum BoundPolarity { /// `Type: Trait` Positive, @@ -3196,7 +3196,7 @@ impl BoundPolarity { /// The constness of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum BoundConstness { /// `Type: Trait` Never, @@ -3218,7 +3218,7 @@ impl BoundConstness { /// The asyncness of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic, Walkable)] +#[derive(HashStable, Walkable)] pub enum BoundAsyncness { /// `Type: Trait` Normal, @@ -3387,7 +3387,7 @@ impl UseTree { /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. #[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub enum AttrStyle { Outer, Inner, @@ -3484,7 +3484,7 @@ impl AttrItemKind { /// /// Currently all early parsed attributes are excluded from pretty printing at rustc_ast_pretty::pprust::state::print_attribute_inline. /// When adding new early parsed attributes, consider whether they should be pretty printed. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable)] pub enum EarlyParsedAttribute { CfgTrace(CfgEntry), CfgAttrTrace, @@ -3607,7 +3607,7 @@ pub struct FieldDef { } /// Was parsing recovery performed? -#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable, Walkable)] pub enum Recovered { No, Yes(ErrorGuaranteed), diff --git a/compiler/rustc_ast/src/attr/data_structures.rs b/compiler/rustc_ast/src/attr/data_structures.rs index 2eab91801cd6d..36d0352b7f8a0 100644 --- a/compiler/rustc_ast/src/attr/data_structures.rs +++ b/compiler/rustc_ast/src/attr/data_structures.rs @@ -1,12 +1,12 @@ use std::fmt; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable}; use rustc_span::{Span, Symbol}; use thin_vec::ThinVec; use crate::attr::version::RustcVersion; -#[derive(Encodable, Decodable, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)] +#[derive(Encodable, Decodable, Clone, Debug, PartialEq, Eq, Hash, HashStable)] pub enum CfgEntry { All(ThinVec, Span), Any(ThinVec, Span), diff --git a/compiler/rustc_ast/src/attr/version.rs b/compiler/rustc_ast/src/attr/version.rs index 59deee40ae28d..c695ba5b8a057 100644 --- a/compiler/rustc_ast/src/attr/version.rs +++ b/compiler/rustc_ast/src/attr/version.rs @@ -1,10 +1,10 @@ use std::fmt::{self, Display}; use std::sync::OnceLock; -use rustc_macros::{BlobDecodable, Encodable, HashStable_Generic, current_rustc_version}; +use rustc_macros::{BlobDecodable, Encodable, HashStable, current_rustc_version}; #[derive(Encodable, BlobDecodable, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub struct RustcVersion { pub major: u16, pub minor: u16, diff --git a/compiler/rustc_ast/src/expand/allocator.rs b/compiler/rustc_ast/src/expand/allocator.rs index 332ad50d927fa..874534b876521 100644 --- a/compiler/rustc_ast/src/expand/allocator.rs +++ b/compiler/rustc_ast/src/expand/allocator.rs @@ -1,7 +1,7 @@ -use rustc_macros::HashStable_Generic; +use rustc_macros::HashStable; use rustc_span::{Symbol, sym}; -#[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable_Generic)] +#[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable)] pub enum AllocatorKind { /// Use `#[global_allocator]` as global allocator. Global, diff --git a/compiler/rustc_ast/src/expand/autodiff_attrs.rs b/compiler/rustc_ast/src/expand/autodiff_attrs.rs index a3c913436ac76..a1967ba8db322 100644 --- a/compiler/rustc_ast/src/expand/autodiff_attrs.rs +++ b/compiler/rustc_ast/src/expand/autodiff_attrs.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use rustc_span::{Symbol, sym}; -use crate::expand::{Decodable, Encodable, HashStable_Generic}; +use crate::expand::{Decodable, Encodable, HashStable}; use crate::{Ty, TyKind}; /// Forward and Reverse Mode are well known names for automatic differentiation implementations. @@ -20,7 +20,7 @@ use crate::{Ty, TyKind}; /// /// Documentation for using [reverse](https://enzyme.mit.edu/rust/rev.html) and /// [forward](https://enzyme.mit.edu/rust/fwd.html) mode is available online. -#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub enum DiffMode { /// No autodiff is applied (used during error handling). Error, @@ -42,7 +42,7 @@ impl DiffMode { /// However, under forward mode we overwrite the previous shadow value, while for reverse mode /// we add to the previous shadow value. To not surprise users, we picked different names. /// Dual numbers is also a quite well known name for forward mode AD types. -#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub enum DiffActivity { /// Implicit or Explicit () return type, so a special case of Const. None, diff --git a/compiler/rustc_ast/src/expand/mod.rs b/compiler/rustc_ast/src/expand/mod.rs index 069bff67b97ac..e5abb651c0800 100644 --- a/compiler/rustc_ast/src/expand/mod.rs +++ b/compiler/rustc_ast/src/expand/mod.rs @@ -1,6 +1,6 @@ //! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`. -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable}; pub mod allocator; pub mod autodiff_attrs; diff --git a/compiler/rustc_ast/src/expand/typetree.rs b/compiler/rustc_ast/src/expand/typetree.rs index e7b4f3aff413a..3c1dd69f6c559 100644 --- a/compiler/rustc_ast/src/expand/typetree.rs +++ b/compiler/rustc_ast/src/expand/typetree.rs @@ -21,9 +21,9 @@ use std::fmt; -use crate::expand::{Decodable, Encodable, HashStable_Generic}; +use crate::expand::{Decodable, Encodable, HashStable}; -#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub enum Kind { Anything, Integer, @@ -35,7 +35,7 @@ pub enum Kind { Unknown, } -#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub struct TypeTree(pub Vec); impl TypeTree { @@ -59,13 +59,13 @@ impl TypeTree { } } -#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub struct FncTree { pub args: Vec, pub ret: TypeTree, } -#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub struct Type { pub offset: isize, pub size: usize, diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 62ec063585171..9f148f87dfba8 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -5,7 +5,7 @@ pub use LitKind::*; pub use NtExprKind::*; pub use NtPatKind::*; pub use TokenKind::*; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable}; use rustc_span::edition::Edition; use rustc_span::symbol::IdentPrintMode; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym}; @@ -17,7 +17,7 @@ use crate::ast; use crate::util::case::Case; /// Represents the kind of doc comment it is, ie `///` or `#[doc = ""]`. -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Debug, HashStable)] pub enum DocFragmentKind { /// A sugared doc comment: `///` or `//!` or `/**` or `/*!`. Sugared(CommentKind), @@ -40,13 +40,13 @@ impl DocFragmentKind { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable)] pub enum CommentKind { Line, Block, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable)] pub enum InvisibleOrigin { // From the expansion of a metavariable in a declarative macro. MetaVar(MetaVarKind), @@ -69,7 +69,7 @@ impl InvisibleOrigin { } /// Annoyingly similar to `NonterminalKind`, but the slight differences are important. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable)] pub enum MetaVarKind { Item, Block, @@ -125,7 +125,7 @@ impl fmt::Display for MetaVarKind { /// Describes how a sequence of token trees is delimited. /// Cannot use `proc_macro::Delimiter` directly because this /// structure should implement some additional traits. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)] pub enum Delimiter { /// `( ... )` Parenthesis, @@ -188,7 +188,7 @@ impl Delimiter { // type. This means that float literals like `1f32` are classified by this type // as `Int`. Only upon conversion to `ast::LitKind` will such a literal be // given the `Float` kind. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable)] pub enum LitKind { Bool, // AST only, must never appear in a `Token` Byte, @@ -205,7 +205,7 @@ pub enum LitKind { } /// A literal token. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable)] pub struct Lit { pub kind: LitKind, pub symbol: Symbol, @@ -351,7 +351,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool { .contains(&name) } -#[derive(PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy, Clone, HashStable_Generic)] +#[derive(PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy, Clone, HashStable)] pub enum IdentIsRaw { No, Yes, @@ -378,7 +378,7 @@ impl From for IdentIsRaw { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable)] pub enum TokenKind { /* Expression-operator symbols. */ /// `=` @@ -528,7 +528,7 @@ pub enum TokenKind { Eof, } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable)] pub struct Token { pub kind: TokenKind, pub span: Span, @@ -1090,7 +1090,7 @@ impl PartialEq for Token { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable)] pub enum NtPatKind { // Matches or-patterns. Was written using `pat` in edition 2021 or later. PatWithOr, @@ -1100,7 +1100,7 @@ pub enum NtPatKind { PatParam { inferred: bool }, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable)] pub enum NtExprKind { // Matches expressions using the post-edition 2024. Was written using // `expr` in edition 2024 or later. @@ -1112,7 +1112,7 @@ pub enum NtExprKind { } /// A macro nonterminal, known in documentation as a fragment specifier. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable)] pub enum NonterminalKind { Item, Block, diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index efd9b500ea0e1..86a6d93dac359 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -12,7 +12,7 @@ use std::{cmp, fmt, iter, mem}; use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher}; use rustc_data_structures::sync; -use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; +use rustc_macros::{Decodable, Encodable, HashStable, Walkable}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym}; use thin_vec::ThinVec; @@ -23,7 +23,7 @@ use crate::token::{self, Delimiter, Token, TokenKind}; use crate::{AttrVec, Attribute}; /// Part of a `TokenStream`. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)] pub enum TokenTree { /// A single token. Should never be `OpenDelim` or `CloseDelim`, because /// delimiters are implicitly represented by `Delimited`. @@ -545,7 +545,7 @@ pub struct AttrsTarget { /// compound token. Used for conversions to `proc_macro::Spacing`. Also used to /// guide pretty-printing, which is where the `JointHidden` value (which isn't /// part of `proc_macro::Spacing`) comes in useful. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)] pub enum Spacing { /// The token cannot join with the following token to form a compound /// token. @@ -967,7 +967,7 @@ impl TokenCursor { } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] +#[derive(Encodable, Decodable, HashStable, Walkable)] pub struct DelimSpan { pub open: Span, pub close: Span, @@ -991,7 +991,7 @@ impl DelimSpan { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)] pub struct DelimSpacing { pub open: Spacing, pub close: Spacing, diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index f18d5a1f190a2..f82c17b4948c1 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -12,7 +12,7 @@ use rustc_ast::{AttrStyle, Path, ast}; use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_hir::LangItem; -use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute}; +use rustc_macros::{Decodable, Encodable, HashStable, PrintAttribute}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, sym}; @@ -26,7 +26,7 @@ use crate::{ DefaultBodyStability, HashIgnoredAttrId, PartialConstStability, RustcVersion, Stability, }; -#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum EiiImplResolution { /// Usually, finding the extern item that an EII implementation implements means finding /// the defid of the associated attribute macro, and looking at *its* attributes to find @@ -39,7 +39,7 @@ pub enum EiiImplResolution { Error(ErrorGuaranteed), } -#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct EiiImpl { pub resolution: EiiImplResolution, pub impl_marked_unsafe: bool, @@ -48,7 +48,7 @@ pub struct EiiImpl { pub is_default: bool, } -#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct EiiDecl { pub foreign_item: DefId, /// whether or not it is unsafe to implement this EII @@ -56,7 +56,7 @@ pub struct EiiDecl { pub name: Ident, } -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, PrintAttribute)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable, PrintAttribute)] pub enum CguKind { No, PreDashLto, @@ -64,7 +64,7 @@ pub enum CguKind { Any, } -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, PrintAttribute)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable, PrintAttribute)] pub enum CguFields { PartitionReused { cfg: Symbol, module: Symbol }, PartitionCodegened { cfg: Symbol, module: Symbol }, @@ -72,7 +72,7 @@ pub enum CguFields { } #[derive(Copy, Clone, PartialEq, Debug, PrintAttribute)] -#[derive(HashStable_Generic, Encodable, Decodable)] +#[derive(HashStable, Encodable, Decodable)] pub enum DivergingFallbackBehavior { /// Always fallback to `()` (aka "always spontaneous decay") ToUnit, @@ -84,7 +84,7 @@ pub enum DivergingFallbackBehavior { } #[derive(Copy, Clone, PartialEq, Debug, PrintAttribute, Default)] -#[derive(HashStable_Generic, Encodable, Decodable)] +#[derive(HashStable, Encodable, Decodable)] pub enum DivergingBlockBehavior { /// This is the current stable behavior: /// @@ -107,7 +107,7 @@ pub enum DivergingBlockBehavior { Unit, } -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, PrintAttribute)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable, PrintAttribute)] pub enum InlineAttr { None, Hint, @@ -131,24 +131,14 @@ impl InlineAttr { } } -#[derive( - Copy, - Clone, - Encodable, - Decodable, - Debug, - PartialEq, - Eq, - HashStable_Generic, - PrintAttribute -)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable, PrintAttribute)] pub enum InstructionSetAttr { ArmA32, ArmT32, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Default, PrintAttribute)] -#[derive(Encodable, Decodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable)] pub enum OptimizeAttr { /// No `#[optimize(..)]` attribute #[default] @@ -167,7 +157,7 @@ impl OptimizeAttr { } } -#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable_Generic, PrintAttribute)] +#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable, PrintAttribute)] pub enum ReprAttr { ReprInt(IntType), ReprRust, @@ -184,13 +174,13 @@ pub enum TransparencyError { } #[derive(Eq, PartialEq, Debug, Copy, Clone)] -#[derive(Encodable, Decodable, HashStable_Generic, PrintAttribute)] +#[derive(Encodable, Decodable, HashStable, PrintAttribute)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy), } -#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)] +#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable, PrintAttribute)] pub struct Deprecation { pub since: DeprecatedSince, /// The note to issue a reason. @@ -202,7 +192,7 @@ pub struct Deprecation { } /// Release in which an API is deprecated. -#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)] +#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable, PrintAttribute)] pub enum DeprecatedSince { RustcVersion(RustcVersion), /// Deprecated in the future ("to be determined"). @@ -219,7 +209,7 @@ pub enum DeprecatedSince { /// Successfully-parsed value of a `#[coverage(..)]` attribute. #[derive(Copy, Debug, Eq, PartialEq, Encodable, Decodable, Clone)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum CoverageAttrKind { On, Off, @@ -227,7 +217,7 @@ pub enum CoverageAttrKind { /// Successfully-parsed value of a `#[rustc_abi(..)]` attribute. #[derive(Copy, Debug, Eq, PartialEq, Encodable, Decodable, Clone)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum RustcAbiAttrKind { Debug, AssertEq, @@ -258,7 +248,7 @@ impl Deprecation { /// `#[used(compiler)]` /// `#[used(linker)]` #[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum UsedBy { Default, Compiler, @@ -266,7 +256,7 @@ pub enum UsedBy { } #[derive(Encodable, Decodable, Clone, Debug, PartialEq, Eq, Hash)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum MacroUseArgs { UseAll, UseSpecific(ThinVec), @@ -278,7 +268,7 @@ impl Default for MacroUseArgs { } } -#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] +#[derive(Debug, Clone, Encodable, Decodable, HashStable)] pub struct StrippedCfgItem { pub parent_scope: ScopeId, pub ident: Ident, @@ -296,7 +286,7 @@ impl StrippedCfgItem { /// /// See for more details about these variants. #[derive(Encodable, Decodable, Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum Linkage { AvailableExternally, Common, @@ -310,7 +300,7 @@ pub enum Linkage { } #[derive(Clone, Copy, Decodable, Debug, Encodable, PartialEq)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum MirDialect { Analysis, Built, @@ -329,7 +319,7 @@ impl IntoDiagArg for MirDialect { } #[derive(Clone, Copy, Decodable, Debug, Encodable, PartialEq)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] pub enum MirPhase { Initial, PostCleanup, @@ -349,17 +339,7 @@ impl IntoDiagArg for MirPhase { /// Different ways that the PE Format can decorate a symbol name. /// From -#[derive( - Copy, - Clone, - Debug, - Encodable, - Decodable, - HashStable_Generic, - PartialEq, - Eq, - PrintAttribute -)] +#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable, PartialEq, Eq, PrintAttribute)] pub enum PeImportNameType { /// IMPORT_ORDINAL /// Uses the ordinal (i.e., a number) rather than the name. @@ -389,7 +369,7 @@ pub enum PeImportNameType { Decodable, PrintAttribute )] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub enum NativeLibKind { /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) Static { @@ -457,7 +437,7 @@ impl NativeLibKind { } } -#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)] +#[derive(Debug, Encodable, Decodable, Clone, HashStable, PrintAttribute)] pub struct LinkEntry { pub span: Span, pub kind: NativeLibKind, @@ -467,14 +447,14 @@ pub struct LinkEntry { pub import_name_type: Option<(PeImportNameType, Span)>, } -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] #[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)] pub enum DebuggerVisualizerType { Natvis, GdbPrettyPrinter, } -#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)] +#[derive(Debug, Encodable, Decodable, Clone, HashStable, PrintAttribute)] pub struct DebugVisualizer { pub span: Span, pub visualizer_type: DebuggerVisualizerType, @@ -482,7 +462,7 @@ pub struct DebugVisualizer { } #[derive(Clone, Copy, Debug, Decodable, Encodable, Eq, PartialEq)] -#[derive(HashStable_Generic, PrintAttribute)] +#[derive(HashStable, PrintAttribute)] #[derive_const(Default)] pub enum RtsanSetting { Nonblocking, @@ -492,7 +472,7 @@ pub enum RtsanSetting { } #[derive(Eq, PartialEq, Debug, Copy, Clone)] -#[derive(Encodable, Decodable, HashStable_Generic, PrintAttribute)] +#[derive(Encodable, Decodable, HashStable, PrintAttribute)] pub enum WindowsSubsystemKind { Console, Windows, @@ -508,20 +488,20 @@ impl WindowsSubsystemKind { } #[derive(Copy, Clone, Debug, PartialEq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub enum DocInline { Inline, NoInline, } #[derive(Copy, Clone, Debug, PartialEq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub enum HideOrShow { Hide, Show, } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct CfgInfo { pub name: Symbol, pub name_span: Span, @@ -538,13 +518,13 @@ impl CfgInfo { } } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct CfgHideShow { pub kind: HideOrShow, pub values: ThinVec, } -#[derive(Clone, Debug, Default, HashStable_Generic, Decodable, PrintAttribute)] +#[derive(Clone, Debug, Default, HashStable, Decodable, PrintAttribute)] pub struct DocAttribute { pub aliases: FxIndexMap, pub hidden: Option, @@ -644,7 +624,7 @@ impl rustc_serialize::Encodable for DocAttribute /// | external | no | if-ext | if-ext | yes | /// | yes | yes | yes | yes | yes | #[derive(Copy, Clone, Debug, Hash, PartialEq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub enum CollapseMacroDebuginfo { /// Don't collapse debuginfo for the macro No = 0, @@ -658,7 +638,7 @@ pub enum CollapseMacroDebuginfo { /// Crate type, as specified by `#![crate_type]` #[derive(Copy, Clone, Debug, Hash, PartialEq, Default, PartialOrd, Eq, Ord)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub enum CrateType { /// `#![crate_type = "bin"]` Executable, @@ -758,7 +738,7 @@ impl IntoDiagArg for CrateType { } } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum RustcLayoutType { Abi, Align, @@ -767,7 +747,7 @@ pub enum RustcLayoutType { Debug, } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq, Eq)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute, PartialEq, Eq)] pub enum RustcMirKind { PeekMaybeInit, PeekMaybeUninit, @@ -777,13 +757,13 @@ pub enum RustcMirKind { BorrowckGraphvizFormat { format: BorrowckGraphvizFormatKind }, } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq, Eq)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute, PartialEq, Eq)] pub enum BorrowckGraphvizFormatKind { TwoPhase, } #[derive(Clone, Debug, PartialEq, Eq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub struct RustcCleanAttribute { pub span: Span, pub cfg: Symbol, @@ -793,14 +773,14 @@ pub struct RustcCleanAttribute { /// Represents the `except=` or `loaded_from_disk=` argument of `#[rustc_clean]` #[derive(Clone, Debug, PartialEq, Eq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub struct RustcCleanQueries { pub entries: ThinVec, pub span: Span, } #[derive(Clone, Debug, PartialEq, Eq)] -#[derive(HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(HashStable, Encodable, Decodable, PrintAttribute)] pub struct RustcAutodiff { /// Conceptually either forward or reverse mode AD, as described in various autodiff papers and /// e.g. in the [JAX @@ -876,7 +856,7 @@ impl RustcAutodiff { } /// We generate one of these structs for each `#[autodiff(...)]` attribute. -#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable)] pub struct AutoDiffItem { /// The name of the function getting differentiated pub source: String, @@ -896,7 +876,7 @@ impl fmt::Display for AutoDiffItem { } } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct LintAttribute { /// See RFC #2383 pub reason: Option, @@ -908,7 +888,7 @@ pub struct LintAttribute { pub lint_instances: ThinVec, } -#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] +#[derive(Debug, Clone, Encodable, Decodable, HashStable)] pub struct LintInstance { /// The span of the `MetaItem` that produced this `LintInstance` span: Span, @@ -1006,13 +986,13 @@ impl LintInstance { } } -#[derive(Debug, Clone, PrintAttribute, Encodable, Decodable, HashStable_Generic)] +#[derive(Debug, Clone, PrintAttribute, Encodable, Decodable, HashStable)] enum LintAttrTool { Present { tool_name: Symbol, full_lint: Symbol }, NoTool, } -#[derive(Clone, Copy, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq)] +#[derive(Clone, Copy, Debug, HashStable, Encodable, Decodable, PrintAttribute, PartialEq)] pub enum LintAttributeKind { Allow, Deny, @@ -1082,7 +1062,7 @@ impl LintAttributeKind { /// [`rustc_parse`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html /// [`rustc_codegen_ssa`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/index.html /// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum AttributeKind { // tidy-alphabetical-start /// Represents `#[allow_internal_unsafe]`. diff --git a/compiler/rustc_hir/src/attrs/diagnostic.rs b/compiler/rustc_hir/src/attrs/diagnostic.rs index 66cdf2be8fc4d..5cea004b01185 100644 --- a/compiler/rustc_hir/src/attrs/diagnostic.rs +++ b/compiler/rustc_hir/src/attrs/diagnostic.rs @@ -3,14 +3,14 @@ use std::fmt; use std::fmt::Debug; pub use rustc_ast::attr::data_structures::*; -use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute}; +use rustc_macros::{Decodable, Encodable, HashStable, PrintAttribute}; use rustc_span::{DesugaringKind, Span, Symbol, kw}; use thin_vec::ThinVec; use tracing::debug; use crate::attrs::PrintAttribute; -#[derive(Clone, Default, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Default, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct Directive { pub is_rustc_attr: bool, pub condition: Option, @@ -123,7 +123,7 @@ pub struct CustomDiagnostic { /// Like [std::fmt::Arguments] this is a string that has been parsed into "pieces", /// either as string pieces or dynamic arguments. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct FormatString { pub input: Symbol, pub span: Span, @@ -224,13 +224,13 @@ pub struct FormatArgs { pub generic_args: Vec<(Symbol, String)>, } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum Piece { Lit(Symbol), Arg(FormatArg), } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum FormatArg { // A generic parameter, like `{T}` if we're on the `From` trait. GenericParam { @@ -250,7 +250,7 @@ pub enum FormatArg { } /// Represents the `on` filter in `#[rustc_on_unimplemented]`. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct OnUnimplementedCondition { pub span: Span, pub pred: Predicate, @@ -275,7 +275,7 @@ impl OnUnimplementedCondition { /// /// It is similar to the predicate in the `cfg` attribute, /// and may contain nested predicates. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum Predicate { /// A condition like `on(crate_local)`. Flag(Flag), @@ -313,7 +313,7 @@ impl Predicate { } /// Represents a `MetaWord` in an `on`-filter. -#[derive(Clone, Copy, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Copy, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum Flag { /// Whether the code causing the trait bound to not be fulfilled /// is part of the user's crate. @@ -328,7 +328,7 @@ pub enum Flag { /// A `MetaNameValueStr` in an `on`-filter. /// /// For example, `#[rustc_on_unimplemented(on(name = "value", message = "hello"))]`. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct NameValue { pub name: Name, /// Something like `"&str"` or `"alloc::string::String"`, @@ -347,7 +347,7 @@ impl NameValue { } /// The valid names of the `on` filter. -#[derive(Clone, Copy, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Copy, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum Name { Cause, FromDesugaring, @@ -367,7 +367,7 @@ pub enum FlagOrNv<'p> { /// If it is a simple literal like this then `pieces` will be `[LitOrArg::Lit("value")]`. /// The `Arg` variant is used when it contains formatting like /// `#[rustc_on_unimplemented(on(Self = "&[{A}]", message = "hello"))]`. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub struct FilterFormatString { pub pieces: ThinVec, } @@ -399,7 +399,7 @@ impl FilterFormatString { } } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable, PrintAttribute)] pub enum LitOrArg { Lit(Symbol), Arg(Symbol), diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 608835dfbe917..863e066f845f0 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -7,7 +7,7 @@ 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, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable}; use rustc_span::Symbol; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::hygiene::MacroKind; @@ -16,7 +16,7 @@ use crate::definitions::DefPathData; use crate::hir; /// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct. -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable)] pub enum CtorOf { /// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit struct. Struct, @@ -25,7 +25,7 @@ pub enum CtorOf { } /// What kind of constructor something is. -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable)] pub enum CtorKind { /// Constructor function automatically created by a tuple struct/variant. Fn, @@ -35,7 +35,7 @@ pub enum CtorKind { /// A set of macro kinds, for macros that can have more than one kind #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Hash, Debug)] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub struct MacroKinds(u8); bitflags::bitflags! { impl MacroKinds: u8 { @@ -81,7 +81,7 @@ impl MacroKinds { } /// An attribute that is not a macro; e.g., `#[inline]` or `#[rustfmt::skip]`. -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable)] pub enum NonMacroAttrKind { /// Single-segment attribute defined by the language (`#[inline]`) Builtin(Symbol), @@ -96,7 +96,7 @@ pub enum NonMacroAttrKind { /// What kind of definition something is; e.g., `mod` vs `struct`. /// `enum DefPathData` may need to be updated if a new variant is added here. -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable)] pub enum DefKind { // Type namespace Mod, @@ -511,7 +511,7 @@ impl DefKind { /// - the call to `str_to_string` will resolve to [`Res::Def`], with the [`DefId`] /// pointing to the definition of `str_to_string` in the current crate. // -#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable)] pub enum Res { /// Definition having a unique ID (`DefId`), corresponds to something defined in user code. /// @@ -679,7 +679,7 @@ impl PartialRes { /// Different kinds of symbols can coexist even if they share the same textual name. /// Therefore, they each have a separate universe (known as a "namespace"). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] -#[derive(HashStable_Generic)] +#[derive(HashStable)] pub enum Namespace { /// The type namespace includes `struct`s, `enum`s, `union`s, `trait`s, and `mod`s /// (and, by extension, crates). @@ -722,7 +722,7 @@ impl ToStableHashKey for Namespace { } /// Just a helper ‒ separate structure for each namespace. -#[derive(Copy, Clone, Default, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Default, Debug, HashStable)] pub struct PerNS { pub value_ns: T, pub type_ns: T, diff --git a/compiler/rustc_hir/src/diagnostic_items.rs b/compiler/rustc_hir/src/diagnostic_items.rs index 5e0915de9d388..c19aeec659795 100644 --- a/compiler/rustc_hir/src/diagnostic_items.rs +++ b/compiler/rustc_hir/src/diagnostic_items.rs @@ -1,11 +1,11 @@ use rustc_data_structures::fx::FxIndexMap; -use rustc_macros::HashStable_Generic; +use rustc_macros::HashStable; use rustc_span::Symbol; use rustc_span::def_id::DefIdMap; use crate::def_id::DefId; -#[derive(Debug, Default, HashStable_Generic)] +#[derive(Debug, Default, HashStable)] pub struct DiagnosticItems { #[stable_hasher(ignore)] pub id_to_name: DefIdMap, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 2ccf9a532b9b3..37db24a955d8d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -21,7 +21,7 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::tagged_ptr::TaggedRef; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_index::IndexVec; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable}; use rustc_span::def_id::LocalDefId; use rustc_span::{ BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, sym, @@ -38,7 +38,7 @@ pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId}; use crate::intravisit::{FnKind, VisitorExt}; use crate::lints::DelayedLints; -#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable)] pub enum AngleBrackets { /// E.g. `Path`. Missing, @@ -48,7 +48,7 @@ pub enum AngleBrackets { Full, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable)] pub enum LifetimeSource { /// E.g. `&Type`, `&'_ Type`, `&'a Type`, `&mut Type`, `&'_ mut Type`, `&'a mut Type` Reference, @@ -72,7 +72,7 @@ pub enum LifetimeSource { Other, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable)] pub enum LifetimeSyntax { /// E.g. `&Type`, `ContainsLifetime` Implicit, @@ -149,7 +149,7 @@ impl From for LifetimeSyntax { /// Some combinations that cannot occur are `LifetimeSyntax::Implicit` with /// `LifetimeSource::OutlivesBound` or `LifetimeSource::PreciseCapturing` /// — there's no way to "elide" these lifetimes. -#[derive(Debug, Copy, Clone, HashStable_Generic)] +#[derive(Debug, Copy, Clone, HashStable)] // Raise the alignment to at least 4 bytes. // This is relied on in other parts of the compiler (for pointer tagging): // @@ -179,7 +179,7 @@ pub struct Lifetime { pub syntax: LifetimeSyntax, } -#[derive(Debug, Copy, Clone, HashStable_Generic)] +#[derive(Debug, Copy, Clone, HashStable)] pub enum ParamName { /// Some user-given name like `T` or `'x`. Plain(Ident), @@ -217,7 +217,7 @@ impl ParamName { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)] pub enum LifetimeKind { /// User-given names or fresh (synthetic) names. Param(LocalDefId), @@ -344,7 +344,7 @@ impl Lifetime { /// A `Path` is essentially Rust's notion of a name; for instance, /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Path<'hir, R = Res> { pub span: Span, /// The resolution for the path. @@ -364,7 +364,7 @@ impl Path<'_> { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct PathSegment<'hir> { /// The identifier portion of this path segment. pub ident: Ident, @@ -401,7 +401,7 @@ impl<'hir> PathSegment<'hir> { } } -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] pub enum ConstItemRhs<'hir> { Body(BodyId), TypeConst(&'hir ConstArg<'hir>), @@ -436,7 +436,7 @@ impl<'hir> ConstItemRhs<'hir> { /// /// For an explanation of the `Unambig` generic parameter see the dev-guide: /// -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] #[repr(C)] pub struct ConstArg<'hir, Unambig = ()> { #[stable_hasher(ignore)] @@ -493,7 +493,7 @@ impl<'hir, Unambig> ConstArg<'hir, Unambig> { } /// See [`ConstArg`]. -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] #[repr(u8, C)] pub enum ConstArgKind<'hir, Unambig = ()> { Tup(&'hir [&'hir ConstArg<'hir, Unambig>]), @@ -521,7 +521,7 @@ pub enum ConstArgKind<'hir, Unambig = ()> { }, } -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] pub struct ConstArgExprField<'hir> { pub hir_id: HirId, pub span: Span, @@ -529,13 +529,13 @@ pub struct ConstArgExprField<'hir> { pub expr: &'hir ConstArg<'hir>, } -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] pub struct ConstArgArrayExpr<'hir> { pub span: Span, pub elems: &'hir [&'hir ConstArg<'hir>], } -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] pub struct InferArg { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -548,7 +548,7 @@ impl InferArg { } } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum GenericArg<'hir> { Lifetime(&'hir Lifetime), Type(&'hir Ty<'hir, AmbigArg>), @@ -611,7 +611,7 @@ impl GenericArg<'_> { } /// The generic arguments and associated item constraints of a path segment. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct GenericArgs<'hir> { /// The generic arguments for this path segment. pub args: &'hir [GenericArg<'hir>], @@ -735,7 +735,7 @@ impl<'hir> GenericArgs<'hir> { } } -#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] pub enum GenericArgsParentheses { No, /// Bounds for `feature(return_type_notation)`, like `T: Trait`, @@ -746,7 +746,7 @@ pub enum GenericArgsParentheses { } /// The modifiers on a trait bound. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub struct TraitBoundModifiers { pub constness: BoundConstness, pub polarity: BoundPolarity, @@ -757,7 +757,7 @@ impl TraitBoundModifiers { TraitBoundModifiers { constness: BoundConstness::Never, polarity: BoundPolarity::Positive }; } -#[derive(Clone, Copy, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Debug, HashStable)] pub enum GenericBound<'hir> { Trait(PolyTraitRef<'hir>), Outlives(&'hir Lifetime), @@ -783,7 +783,7 @@ impl GenericBound<'_> { pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>]; -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, Debug)] pub enum MissingLifetimeKind { /// An explicit `'_`. Underscore, @@ -795,7 +795,7 @@ pub enum MissingLifetimeKind { Brackets, } -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared (e.g., in // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`). @@ -809,7 +809,7 @@ pub enum LifetimeParamKind { Error, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum GenericParamKind<'hir> { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime { @@ -826,7 +826,7 @@ pub enum GenericParamKind<'hir> { }, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct GenericParam<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -865,7 +865,7 @@ impl<'hir> GenericParam<'hir> { /// early-bound (but can be a late-bound lifetime in functions, for example), /// or from a `for<...>` binder, in which case it's late-bound (and notably, /// does not show up in the parent item's generics). -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum GenericParamSource { // Early or late-bound parameters defined on an item Generics, @@ -883,7 +883,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Generics<'hir> { pub params: &'hir [GenericParam<'hir>], pub predicates: &'hir [WherePredicate<'hir>], @@ -1090,7 +1090,7 @@ impl<'hir> Generics<'hir> { } /// A single predicate in a where-clause. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct WherePredicate<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1099,7 +1099,7 @@ pub struct WherePredicate<'hir> { } /// The kind of a single predicate in a where-clause. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum WherePredicateKind<'hir> { /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate<'hir>), @@ -1127,7 +1127,7 @@ impl<'hir> WherePredicateKind<'hir> { } } -#[derive(Copy, Clone, Debug, HashStable_Generic, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, HashStable, PartialEq, Eq)] pub enum PredicateOrigin { WhereClause, GenericParam, @@ -1135,7 +1135,7 @@ pub enum PredicateOrigin { } /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct WhereBoundPredicate<'hir> { /// Origin of the predicate. pub origin: PredicateOrigin, @@ -1155,7 +1155,7 @@ impl<'hir> WhereBoundPredicate<'hir> { } /// A lifetime predicate (e.g., `'a: 'b + 'c`). -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct WhereRegionPredicate<'hir> { pub in_where_clause: bool, pub lifetime: &'hir Lifetime, @@ -1170,7 +1170,7 @@ impl<'hir> WhereRegionPredicate<'hir> { } /// An equality predicate (e.g., `T = int`); currently unsupported. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct WhereEqPredicate<'hir> { pub lhs_ty: &'hir Ty<'hir>, pub rhs_ty: &'hir Ty<'hir>, @@ -1186,7 +1186,7 @@ pub struct ParentedNode<'tcx> { } /// Arguments passed to an attribute macro. -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable)] pub enum AttrArgs { /// No arguments: `#[attr]`. Empty, @@ -1201,7 +1201,7 @@ pub enum AttrArgs { }, } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable)] pub struct AttrPath { pub segments: Box<[Symbol]>, pub span: Span, @@ -1237,7 +1237,7 @@ impl fmt::Display for AttrPath { } } -#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, Debug, HashStable, Encodable, Decodable)] pub struct AttrItem { // Not lowered to hir::Path because we have no NodeId to resolve to. pub path: AttrPath, @@ -1259,7 +1259,7 @@ pub struct HashIgnoredAttrId { /// Many functions on this type have their documentation in the [`AttributeExt`] trait, /// since they defer their implementation directly to that trait. -#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Debug, Encodable, Decodable, HashStable)] pub enum Attribute { /// A parsed built-in attribute. /// @@ -1631,7 +1631,7 @@ impl fmt::Debug for OwnerNodes<'_> { } /// Full information resulting from lowering an AST node. -#[derive(Debug, HashStable_Generic)] +#[derive(Debug, HashStable)] pub struct OwnerInfo<'hir> { /// Contents of the HIR. pub nodes: OwnerNodes<'hir>, @@ -1655,7 +1655,7 @@ impl<'tcx> OwnerInfo<'tcx> { } } -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum MaybeOwner<'tcx> { Owner(&'tcx OwnerInfo<'tcx>), NonOwner(HirId), @@ -1676,7 +1676,7 @@ impl<'tcx> MaybeOwner<'tcx> { } } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Closure<'hir> { pub def_id: LocalDefId, pub binder: ClosureBinder, @@ -1692,7 +1692,7 @@ pub struct Closure<'hir> { pub kind: ClosureKind, } -#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable, Encodable, Decodable)] pub enum ClosureKind { /// This is a plain closure expression. Closure, @@ -1711,7 +1711,7 @@ pub enum ClosureKind { /// A block of statements `{ .. }`, which may have a label (in this case the /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// the `rules` being anything but `DefaultBlock`. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Block<'hir> { /// Statements in a block. pub stmts: &'hir [Stmt<'hir>], @@ -1740,13 +1740,13 @@ impl<'hir> Block<'hir> { } } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct TyFieldPath { pub variant: Option, pub field: Ident, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct TyPat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1754,7 +1754,7 @@ pub struct TyPat<'hir> { pub span: Span, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Pat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1902,7 +1902,7 @@ impl<'hir> Pat<'hir> { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except `is_shorthand` is true. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct PatField<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1914,7 +1914,7 @@ pub struct PatField<'hir> { pub span: Span, } -#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic, Hash, Eq, Encodable, Decodable)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable, Hash, Eq, Encodable, Decodable)] pub enum RangeEnd { Included, Excluded, @@ -1932,7 +1932,7 @@ impl fmt::Display for RangeEnd { // Equivalent to `Option`. That type takes up 16 bytes on 64-bit, but // this type only takes up 4 bytes, at the cost of being restricted to a // maximum value of `u32::MAX - 1`. In practice, this is more than enough. -#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)] pub struct DotDotPos(u32); impl DotDotPos { @@ -1958,7 +1958,7 @@ impl fmt::Debug for DotDotPos { } } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct PatExpr<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1966,7 +1966,7 @@ pub struct PatExpr<'hir> { pub kind: PatExprKind<'hir>, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum PatExprKind<'hir> { Lit { lit: Lit, @@ -1976,7 +1976,7 @@ pub enum PatExprKind<'hir> { Path(QPath<'hir>), } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum TyPatKind<'hir> { /// A range pattern (e.g., `1..=2` or `1..2`). Range(&'hir ConstArg<'hir>, &'hir ConstArg<'hir>), @@ -1991,7 +1991,7 @@ pub enum TyPatKind<'hir> { Err(ErrorGuaranteed), } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum PatKind<'hir> { /// A missing pattern, e.g. for an anonymous param in a bare fn like `fn f(u32)`. Missing, @@ -2066,7 +2066,7 @@ pub enum PatKind<'hir> { } /// A statement. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Stmt<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2075,7 +2075,7 @@ pub struct Stmt<'hir> { } /// The contents of a statement. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum StmtKind<'hir> { /// A local (`let`) binding. Let(&'hir LetStmt<'hir>), @@ -2091,7 +2091,7 @@ pub enum StmtKind<'hir> { } /// Represents a `let` statement (i.e., `let : = ;`). -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct LetStmt<'hir> { /// Span of `super` in `super let`. pub super_: Option, @@ -2113,7 +2113,7 @@ pub struct LetStmt<'hir> { /// Represents a single arm of a `match` expression, e.g. /// ` (if ) => `. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Arm<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2131,7 +2131,7 @@ pub struct Arm<'hir> { /// /// In an `if let`, imagine it as `if (let = ) { ... }`; in a let-else, it is part of /// the desugaring to if-let. Only let-else supports the type annotation at present. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct LetExpr<'hir> { pub span: Span, pub pat: &'hir Pat<'hir>, @@ -2142,7 +2142,7 @@ pub struct LetExpr<'hir> { pub recovered: ast::Recovered, } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct ExprField<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2152,19 +2152,19 @@ pub struct ExprField<'hir> { pub is_shorthand: bool, } -#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), } -#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub struct BodyId { pub hir_id: HirId, } @@ -2190,7 +2190,7 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Body<'hir> { pub params: &'hir [Param<'hir>], pub value: &'hir Expr<'hir>, @@ -2203,7 +2203,7 @@ impl<'hir> Body<'hir> { } /// The type of source expression that caused this coroutine to be created. -#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable, Encodable, Decodable)] pub enum CoroutineKind { /// A coroutine that comes from a desugaring. Desugared(CoroutineDesugaring, CoroutineSource), @@ -2253,7 +2253,7 @@ impl fmt::Display for CoroutineKind { /// /// This helps error messages but is also used to drive coercions in /// type-checking (see #60424). -#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy, HashStable, Encodable, Decodable)] pub enum CoroutineSource { /// An explicit `async`/`gen` block written by the user. Block, @@ -2276,7 +2276,7 @@ impl fmt::Display for CoroutineSource { } } -#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)] +#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable, Encodable, Decodable)] pub enum CoroutineDesugaring { /// An explicit `async` block or the body of an `async` function. Async, @@ -2416,7 +2416,7 @@ pub type Lit = Spanned; /// /// You can check if this anon const is a default in a const param /// `const N: usize = { ... }` with `tcx.hir_opt_const_param_default_param_def_id(..)` -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, HashStable)] pub struct AnonConst { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2426,7 +2426,7 @@ pub struct AnonConst { } /// An inline constant expression `const { something }`. -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, HashStable)] pub struct ConstBlock { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2442,7 +2442,7 @@ pub struct ConstBlock { /// the compiler and the reference. /// /// [rust lang reference]: https://doc.rust-lang.org/reference/expressions.html -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub struct Expr<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -2801,7 +2801,7 @@ pub fn expr_needs_parens(expr: &Expr<'_>) -> bool { } } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum ExprKind<'hir> { /// Allow anonymous constants from an inline `const` block ConstBlock(ConstBlock), @@ -2940,7 +2940,7 @@ pub enum ExprKind<'hir> { Err(rustc_span::ErrorGuaranteed), } -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum StructTailExpr<'hir> { /// A struct expression where all the fields are explicitly enumerated: `Foo { a, b }`. None, @@ -2964,7 +2964,7 @@ pub enum StructTailExpr<'hir> { /// To resolve the path to a `DefId`, call [`qpath_res`]. /// /// [`qpath_res`]: ../../rustc_middle/ty/struct.TypeckResults.html#method.qpath_res -#[derive(Debug, Clone, Copy, HashStable_Generic)] +#[derive(Debug, Clone, Copy, HashStable)] pub enum QPath<'hir> { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -3003,7 +3003,7 @@ impl<'hir> QPath<'hir> { } /// Hints at the original code for a let statement. -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum LocalSource { /// A `match _ { .. }`. Normal, @@ -3027,7 +3027,7 @@ pub enum LocalSource { } /// Hints at the original code for a `match _ { .. }`. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic, Encodable, Decodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, Encodable, Decodable)] pub enum MatchSource { /// A `match _ { .. }`. Normal, @@ -3059,7 +3059,7 @@ impl MatchSource { } /// The loop type that yielded an `ExprKind::Loop`. -#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable)] pub enum LoopSource { /// A `loop { .. }` loop. Loop, @@ -3079,7 +3079,7 @@ impl LoopSource { } } -#[derive(Copy, Clone, Debug, PartialEq, HashStable_Generic)] +#[derive(Copy, Clone, Debug, PartialEq, HashStable)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -3098,7 +3098,7 @@ impl fmt::Display for LoopIdError { } } -#[derive(Copy, Clone, Debug, PartialEq, HashStable_Generic)] +#[derive(Copy, Clone, Debug, PartialEq, HashStable)] pub struct Destination { /// This is `Some(_)` iff there is an explicit user-specified 'label pub label: Option