diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 253dff6f8e75c..42e272fdafb5d 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -67,12 +67,6 @@ pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorErro #[cfg(feature = "nightly")] pub use layout::{Layout, TyAbiInterface, TyAndLayout}; -/// Requirements for a `StableHashingContext` to be used in this crate. -/// This is a hack to allow using the `HashStable_Generic` derive macro -/// instead of implementing everything in `rustc_middle`. -#[cfg(feature = "nightly")] -pub trait HashStableContext {} - #[derive(Clone, Copy, PartialEq, Eq, Default)] #[cfg_attr( feature = "nightly", diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 71ec1c5042fda..87633cade1b6a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -31,7 +31,8 @@ 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, Ident, Span, Spanned, Symbol, kw, respan, sym, + ByteSymbol, DUMMY_SP, ErrorGuaranteed, HashStableContext, Ident, Span, Spanned, Symbol, kw, + respan, sym, }; use thin_vec::{ThinVec, thin_vec}; @@ -120,7 +121,7 @@ impl PartialEq<&[Symbol]> for Path { } } -impl HashStable for Path { +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 { diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index ac3e77b0b5d6f..4178db1bfb09d 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -36,8 +36,3 @@ pub mod visit; pub use self::ast::*; pub use self::ast_traits::{AstNodeWrapper, HasAttrs, HasNodeId, HasTokens}; - -/// Requirements for a `StableHashingContext` to be used in this crate. -/// This is a hack to allow using the `HashStable_Generic` derive macro -/// instead of implementing everything in `rustc_middle`. -pub trait HashStableContext: rustc_span::HashStableContext {} diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 8953391ac58bf..06bd6f03e9350 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -14,7 +14,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; use rustc_serialize::{Decodable, Encodable}; -use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym}; +use rustc_span::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, Symbol, sym}; use thin_vec::ThinVec; use crate::ast::AttrStyle; @@ -826,7 +826,7 @@ impl FromIterator for TokenStream { impl HashStable for TokenStream where - Hcx: crate::HashStableContext, + Hcx: HashStableContext, { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { for sub_tt in self.iter() { diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 78bd709dd4844..cae8bb89233b2 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -8,9 +8,9 @@ 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_span::Symbol; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::hygiene::MacroKind; +use rustc_span::{HashStableContext, Symbol}; use crate::definitions::DefPathData; use crate::hir; @@ -712,7 +712,7 @@ impl IntoDiagArg for Namespace { } } -impl ToStableHashKey for Namespace { +impl ToStableHashKey for Namespace { type KeyType = Namespace; #[inline] diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 9c2fec8677854..c2d9f879cd601 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -43,7 +43,6 @@ pub use hir::*; pub use lang_items::{LangItem, LanguageItems}; pub use rustc_ast::attr::version::*; pub use stability::*; -pub use stable_hash_impls::HashStableContext; pub use target::{MethodKind, Target}; arena_types!(rustc_arena::declare_arena); diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index 58649a694880b..a157fc0ccbb0c 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,4 +1,5 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_span::HashStableContext; use rustc_span::def_id::DefPathHash; use crate::HashIgnoredAttrId; @@ -8,53 +9,48 @@ use crate::hir::{ use crate::hir_id::ItemLocalId; use crate::lints::DelayedLints; -/// Requirements for a `StableHashingContext` to be used in this crate. -/// This is a hack to allow using the `HashStable_Generic` derive macro -/// instead of implementing everything in `rustc_middle`. -pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStableContext {} - -impl ToStableHashKey for BodyId { +impl ToStableHashKey for BodyId { type KeyType = (DefPathHash, ItemLocalId); #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { + fn to_stable_hash_key(&self, hcx: &Hcx) -> (DefPathHash, ItemLocalId) { let BodyId { hir_id } = *self; hir_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ItemId { +impl ToStableHashKey for ItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for TraitItemId { +impl ToStableHashKey for TraitItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ImplItemId { +impl ToStableHashKey for ImplItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } -impl ToStableHashKey for ForeignItemId { +impl ToStableHashKey for ForeignItemId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { self.owner_id.def_id.to_stable_hash_key(hcx) } } @@ -66,8 +62,8 @@ impl ToStableHashKey for ForeignItemId // want to pick up on a reference changing its target, so we hash the NodeIds // in "DefPath Mode". -impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<'tcx> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { +impl<'tcx, Hcx: HashStableContext> 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 @@ -78,15 +74,15 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<' } } -impl HashStable for DelayedLints { - fn hash_stable(&self, hcx: &mut HirCtx, 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, HirCtx: crate::HashStableContext> HashStable for AttributeMap<'tcx> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { +impl<'tcx, Hcx: HashStableContext> 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; @@ -94,8 +90,8 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for AttributeMap } } -impl HashStable for HashIgnoredAttrId { - fn hash_stable(&self, _hcx: &mut HirCtx, _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 ffff3f979f9e3..064ce4ed4cafe 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -8,7 +8,7 @@ use std::fmt::{self, Debug}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -pub use rustc_span::HashStableContext; +use rustc_span::HashStableContext; use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] @@ -176,7 +176,7 @@ 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] diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index af1d1854fa5a0..1c86d553f9b6a 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -8,11 +8,11 @@ use rustc_data_structures::stable_hasher::{ HashStable, StableCompare, StableHasher, ToStableHashKey, }; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; -use rustc_hir_id::{HashStableContext, HirId, ItemLocalId}; +use rustc_hir_id::{HirId, ItemLocalId}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::def_id::DefPathHash; pub use rustc_span::edition::Edition; -use rustc_span::{Ident, Span, Symbol, sym}; +use rustc_span::{HashStableContext, Ident, Span, Symbol, sym}; use serde::{Deserialize, Serialize}; pub use self::Level::*; diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index fa67adb406ed2..adb93e375c32c 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -84,7 +84,7 @@ fn hash_stable_derive_with_mode( match mode { HashStableMode::Normal => {} HashStableMode::Generic => { - s.add_where_predicate(parse_quote! { __CTX: crate::HashStableContext }); + s.add_where_predicate(parse_quote! { __CTX: ::rustc_span::HashStableContext }); } HashStableMode::NoContext => {} } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ad56e462d2934..814b333cfb0f8 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -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, Span}; +use rustc_span::{ErrorGuaranteed, ExpnId, HashStableContext, Span}; use crate::query::Providers; use crate::ty::{ResolverAstLowering, TyCtxt}; @@ -77,8 +77,8 @@ impl<'hir> Crate<'hir> { } } -impl HashStable for Crate<'_> { - fn hash_stable(&self, hcx: &mut HirCtx, 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 2e118dc3359fa..0e1cee2970f71 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -6,7 +6,7 @@ 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, Pos, Span}; +use rustc_span::{CachingSourceMapView, DUMMY_SP, HashStableContext, Pos, Span}; // Very often, we are hashing something that does not need the `CachingSourceMapView`, so we // initialize it lazily. @@ -73,7 +73,7 @@ impl<'a> StableHashingContext<'a> { } } -impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { +impl<'a> HashStableContext for StableHashingContext<'a> { /// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that /// would be similar to hashing pointers, since those are just offsets into the `SourceMap`). /// Instead, we hash the (file name, line, column) triple, which stays the same even if the @@ -189,8 +189,3 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { ); } } - -impl<'a> rustc_abi::HashStableContext for StableHashingContext<'a> {} -impl<'a> rustc_ast::HashStableContext for StableHashingContext<'a> {} -impl<'a> rustc_hir::HashStableContext for StableHashingContext<'a> {} -impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {} diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index e37247d7dd837..1e95482a8c7e6 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -23,7 +23,8 @@ 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, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym, + FileName, HashStableContext, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, + Symbol, sym, }; use rustc_target::spec::{ FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo, @@ -38,7 +39,7 @@ use crate::errors::FileWriteFail; pub use crate::options::*; use crate::search_paths::SearchPath; use crate::utils::CanonicalizedPath; -use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint}; +use crate::{EarlyDiagCtxt, Session, filesearch, lint}; mod cfg; mod externs; diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 1741dde90f5cf..04e12f1afce68 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -11,30 +11,21 @@ #![recursion_limit = "256"] // tidy-alphabetical-end -pub mod errors; - -pub mod utils; +pub use getopts; pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass}; pub use rustc_lint_defs as lint; -pub mod parse; +pub use session::*; pub mod code_stats; +pub mod errors; +pub mod parse; +pub mod utils; #[macro_use] pub mod config; pub mod cstore; pub mod filesearch; mod macros; mod options; +pub mod output; pub mod search_paths; - mod session; -pub use session::*; - -pub mod output; - -pub use getopts; - -/// Requirements for a `StableHashingContext` to be used in this crate. -/// This is a hack to allow using the `HashStable_Generic` derive macro -/// instead of implementing everything in `rustc_middle`. -pub trait HashStableContext: rustc_ast::HashStableContext + rustc_hir::HashStableContext {} diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 6794ffb311e32..97de708290fb4 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2796,10 +2796,10 @@ impl InnerSpan { } } -/// Requirements for a `StableHashingContext` to be used in this crate. -/// -/// This is a hack to allow using the [`HashStable_Generic`] derive macro -/// instead of implementing everything in rustc_middle. +/// This trait lets `HashStable` and `derive(HashStable_Generic)` be used in +/// this crate (and other crates upstream of `rustc_middle`), while leaving +/// certain operations to be defined in `rustc_middle` where more things are +/// visible. pub trait HashStableContext { /// The main event: stable hashing of a span. fn span_hash_stable(&mut self, span: Span, hasher: &mut StableHasher); diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index 1dc62cb3659cc..d46802bf45d1a 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -24,8 +24,6 @@ pub mod target_features; #[cfg(test)] mod tests; -use rustc_abi::HashStableContext; - /// The name of rustc's own place to organize libraries. /// /// Used to be `rustc`, now the default is `rustlib`.