From 516ac2a5ad5289b8a77dc915edd6078b6d64b611 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Apr 2026 07:18:07 +1100 Subject: [PATCH 1/3] Use interior mutability for `StableHashingContext::caching_source_map`. `StableHashingContext::caching_source_map` is currently externally mutated by `span_hash_stable`, which is reachable from many `hash_stable` methods. But the mutation that happens is just some internal caching, via `CachingSourceMap`. Conceptually it feels like a read-only lookup of source map data. This commit changes the field to interior mutability. This will let `hash_stable` use `&Hcx` instead of `&mut Hcx`. The switch involves replacing the existing `StableHashingContext::source_map` method with a new `StableHashingContxt::span_data_to_lines_and_cols` method, because returning a `&mut` was problematic with the use of `RefCell`. The existing `CachingSourceMapView::span_data_to_lines_and_cols` now returns an `Arc`, but that seems fine because the nearby `CachingSourceMapView::byte_pos_to_line_and_col` already does that. --- compiler/rustc_middle/src/ich/hcx.rs | 32 +++++++++++-------- .../rustc_span/src/caching_source_map_view.rs | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index 2e118dc3359fa..d0491aad45317 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -1,18 +1,19 @@ +use std::cell::RefCell; use std::hash::Hash; +use std::sync::Arc; use rustc_data_structures::stable_hasher::{HashStable, HashingControls, 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, Pos, Span}; +use rustc_span::{BytePos, CachingSourceMapView, DUMMY_SP, Pos, SourceFile, Span, SpanData}; // Very often, we are hashing something that does not need the `CachingSourceMapView`, so we // initialize it lazily. #[derive(Clone)] enum CachingSourceMap<'a> { - Unused(&'a SourceMap), + Unused(&'a Session), InUse(CachingSourceMapView<'a>), } @@ -26,7 +27,7 @@ pub struct StableHashingContext<'a> { // The value of `-Z incremental-ignore-spans`. // This field should only be used by `unstable_opts_incremental_ignore_span` incremental_ignore_spans: bool, - caching_source_map: CachingSourceMap<'a>, + caching_source_map: RefCell>, hashing_controls: HashingControls, } @@ -38,7 +39,7 @@ impl<'a> StableHashingContext<'a> { StableHashingContext { untracked, incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans, - caching_source_map: CachingSourceMap::Unused(sess.source_map()), + caching_source_map: RefCell::new(CachingSourceMap::Unused(sess)), hashing_controls: HashingControls { hash_spans: hash_spans_initial }, } } @@ -51,13 +52,18 @@ impl<'a> StableHashingContext<'a> { self.hashing_controls.hash_spans = prev_hash_spans; } - #[inline] - fn source_map(&mut self) -> &mut CachingSourceMapView<'a> { - match self.caching_source_map { - CachingSourceMap::InUse(ref mut sm) => sm, - CachingSourceMap::Unused(sm) => { - self.caching_source_map = CachingSourceMap::InUse(CachingSourceMapView::new(sm)); - self.source_map() // this recursive call will hit the `InUse` case + fn span_data_to_lines_and_cols( + &self, + span_data: &SpanData, + ) -> Option<(Arc, usize, BytePos, usize, BytePos)> { + let mut caching_source_map = self.caching_source_map.borrow_mut(); + match *caching_source_map { + CachingSourceMap::InUse(ref mut csmv) => csmv.span_data_to_lines_and_cols(span_data), + CachingSourceMap::Unused(sess) => { + let mut csmv = CachingSourceMapView::new(sess.source_map()); + let res = csmv.span_data_to_lines_and_cols(span_data); + *caching_source_map = CachingSourceMap::InUse(csmv); + res } } } @@ -120,7 +126,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { // If this is not an empty or invalid span, we want to hash the last position that belongs // to it, as opposed to hashing the first position past it. let Some((file, line_lo, col_lo, line_hi, col_hi)) = - self.source_map().span_data_to_lines_and_cols(&span) + self.span_data_to_lines_and_cols(&span) else { Hash::hash(&TAG_INVALID_SPAN, hasher); return; diff --git a/compiler/rustc_span/src/caching_source_map_view.rs b/compiler/rustc_span/src/caching_source_map_view.rs index d9aa73cefc578..297d65fd5c273 100644 --- a/compiler/rustc_span/src/caching_source_map_view.rs +++ b/compiler/rustc_span/src/caching_source_map_view.rs @@ -82,13 +82,13 @@ impl<'sm> CachingSourceMapView<'sm> { pub fn span_data_to_lines_and_cols( &mut self, span_data: &SpanData, - ) -> Option<(&SourceFile, usize, BytePos, usize, BytePos)> { + ) -> Option<(Arc, usize, BytePos, usize, BytePos)> { let lo_hit = self.line_bounds.contains(&span_data.lo); let hi_hit = self.line_bounds.contains(&span_data.hi); if lo_hit && hi_hit { // span_data.lo and span_data.hi are cached (i.e. both in the same line). return Some(( - &self.file, + Arc::clone(&self.file), self.line_number, span_data.lo - self.line_bounds.start, self.line_number, @@ -138,7 +138,7 @@ impl<'sm> CachingSourceMapView<'sm> { assert!(self.file.contains(span_data.hi)); Some(( - &self.file, + Arc::clone(&self.file), lo_line_number, span_data.lo - lo_line_bounds.start, hi_line_number, From bd9b5ae92c7e2b78e3502277ff9aaff575a60c88 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Apr 2026 07:23:19 +1100 Subject: [PATCH 2/3] Pass `&hcx` instead of `&mut Hcx` to `hash_stable`. This was enabled by the previous commit. A few related functions also get a similar change. --- compiler/rustc_abi/src/extern_abi.rs | 4 +- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast/src/tokenstream.rs | 4 +- compiler/rustc_ast_lowering/src/lib.rs | 4 +- .../rustc_codegen_cranelift/src/driver/aot.rs | 2 +- compiler/rustc_codegen_llvm/src/common.rs | 4 +- compiler/rustc_codegen_ssa/src/common.rs | 2 +- compiler/rustc_data_structures/src/intern.rs | 2 +- compiler/rustc_data_structures/src/packed.rs | 2 +- .../rustc_data_structures/src/sorted_map.rs | 2 +- .../src/stable_hasher.rs | 74 +++++++++---------- .../src/stable_hasher/tests.rs | 2 +- compiler/rustc_data_structures/src/steal.rs | 2 +- .../rustc_data_structures/src/tagged_ptr.rs | 2 +- .../src/tagged_ptr/tests.rs | 6 +- compiler/rustc_data_structures/src/unord.rs | 8 +- compiler/rustc_hir/src/lang_items.rs | 2 +- compiler/rustc_hir/src/stable_hash_impls.rs | 8 +- compiler/rustc_hir_id/src/lib.rs | 2 +- compiler/rustc_index_macros/src/newtype.rs | 12 ++- compiler/rustc_lint_defs/src/lib.rs | 4 +- compiler/rustc_macros/src/hash_stable.rs | 2 +- .../src/dep_graph/dep_node_key.rs | 4 +- compiler/rustc_middle/src/dep_graph/graph.rs | 15 ++-- compiler/rustc_middle/src/hir/map.rs | 20 ++--- compiler/rustc_middle/src/hir/mod.rs | 14 ++-- compiler/rustc_middle/src/ich/hcx.rs | 2 +- compiler/rustc_middle/src/ich/impls_syntax.rs | 12 +-- compiler/rustc_middle/src/middle/privacy.rs | 2 +- compiler/rustc_middle/src/mir/basic_blocks.rs | 2 +- compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/query/inner.rs | 4 +- .../rustc_middle/src/query/on_disk_cache.rs | 4 +- compiler/rustc_middle/src/query/plumbing.rs | 2 +- compiler/rustc_middle/src/ty/adt.rs | 2 +- compiler/rustc_middle/src/ty/consts/int.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 4 +- compiler/rustc_middle/src/ty/impls_ty.rs | 12 +-- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/verify_ich.rs | 7 +- compiler/rustc_query_impl/src/execution.rs | 8 +- compiler/rustc_span/src/def_id.rs | 6 +- compiler/rustc_span/src/hygiene.rs | 14 ++-- compiler/rustc_span/src/lib.rs | 4 +- compiler/rustc_span/src/symbol.rs | 4 +- compiler/rustc_symbol_mangling/src/hashed.rs | 4 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_type_ir/src/const_kind.rs | 2 +- compiler/rustc_type_ir/src/fast_reject.rs | 4 +- compiler/rustc_type_ir/src/region_kind.rs | 2 +- compiler/rustc_type_ir/src/ty_info.rs | 2 +- compiler/rustc_type_ir/src/ty_kind.rs | 2 +- 52 files changed, 162 insertions(+), 156 deletions(-) diff --git a/compiler/rustc_abi/src/extern_abi.rs b/compiler/rustc_abi/src/extern_abi.rs index 9173245d8aa4e..24dfadcd945ee 100644 --- a/compiler/rustc_abi/src/extern_abi.rs +++ b/compiler/rustc_abi/src/extern_abi.rs @@ -217,9 +217,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, _: &Hcx, hasher: &mut StableHasher) { Hash::hash(self, hasher); } } diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 71ec1c5042fda..2dc44e8759861 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -121,7 +121,7 @@ impl PartialEq<&[Symbol]> for Path { } impl HashStable for Path { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 8953391ac58bf..c006724d85336 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -139,7 +139,7 @@ impl Decodable for LazyAttrTokenStream { } impl HashStable for LazyAttrTokenStream { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &Hcx, _hasher: &mut StableHasher) { panic!("Attempted to compute stable hash for LazyAttrTokenStream"); } } @@ -828,7 +828,7 @@ impl HashStable for TokenStream where Hcx: crate::HashStableContext, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { for sub_tt in self.iter() { sub_tt.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5fcc8f0161194..f2eab2befe26c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -602,9 +602,9 @@ fn compute_hir_hash( .collect(); hir_body_nodes.sort_unstable_by_key(|bn| bn.0); - tcx.with_stable_hashing_context(|mut hcx| { + tcx.with_stable_hashing_context(|hcx| { let mut stable_hasher = StableHasher::new(); - hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher); + hir_body_nodes.hash_stable(&hcx, &mut stable_hasher); stable_hasher.finish() }) } diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index b855e1fa4b780..2ff859e431c77 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -46,7 +46,7 @@ enum OngoingModuleCodegen { } impl HashStable for OngoingModuleCodegen { - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { + fn hash_stable(&self, _: &Hcx, _: &mut StableHasher) { // do nothing } } diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index a134e97cc8915..362d0b26bbfee 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -302,9 +302,9 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { }; if !self.sess().fewer_names() && llvm::get_value_name(value).is_empty() { - let hash = self.tcx.with_stable_hashing_context(|mut hcx| { + let hash = self.tcx.with_stable_hashing_context(|hcx| { let mut hasher = StableHasher::new(); - alloc.hash_stable(&mut hcx, &mut hasher); + alloc.hash_stable(&hcx, &mut hasher); hasher.finish::() }); llvm::set_value_name( diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index de79acd165f0f..497935ef8caec 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -103,7 +103,7 @@ mod temp_stable_hash_impls { use crate::ModuleCodegen; impl HashStable for ModuleCodegen { - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { + fn hash_stable(&self, _: &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..46faf1cb3fca2 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -107,7 +107,7 @@ impl HashStable for Interned<'_, T> where T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..d3a1581e8980b 100644 --- a/compiler/rustc_data_structures/src/packed.rs +++ b/compiler/rustc_data_structures/src/packed.rs @@ -62,7 +62,7 @@ impl fmt::UpperHex for Pu128 { impl HashStable for Pu128 { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..fdbd10c3985e3 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -349,7 +349,7 @@ impl FromIterator<(K, V)> for SortedMap { impl + StableOrd, V: HashStable, Hcx> HashStable for SortedMap { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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 c9993d106d6d3..105dae805ef21 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -42,7 +42,7 @@ pub use rustc_stable_hash::{ /// `StableHasher` takes care of endianness and `isize`/`usize` platform /// differences. pub trait HashStable { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher); } /// Implement this for types that can be turned into stable keys like, for @@ -138,7 +138,7 @@ macro_rules! impl_stable_traits_for_trivial_type { ($t:ty) => { impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut $crate::stable_hasher::StableHasher) { + fn hash_stable(&self, _: &Hcx, hasher: &mut $crate::stable_hasher::StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -179,7 +179,7 @@ impl_stable_traits_for_trivial_type!(Hash64); // hashing we want to hash the full 128-bit hash. impl HashStable for Hash128 { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &Hcx, hasher: &mut StableHasher) { self.as_u128().hash(hasher); } } @@ -193,38 +193,38 @@ impl StableOrd for Hash128 { } impl HashStable for ! { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &Hcx, _hasher: &mut StableHasher) { unreachable!() } } impl HashStable for PhantomData { - fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {} + fn hash_stable(&self, _hcx: &Hcx, _hasher: &mut StableHasher) {} } impl HashStable for NonZero { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.get().hash_stable(hcx, hasher) } } impl HashStable for NonZero { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.get().hash_stable(hcx, hasher) } } impl HashStable for f32 { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { let val: u64 = self.to_bits(); val.hash_stable(hcx, hasher); } @@ -232,21 +232,21 @@ impl HashStable for f64 { impl HashStable for ::std::cmp::Ordering { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (*self as i8).hash_stable(hcx, hasher); } } impl, Hcx> HashStable for (T1,) { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -267,7 +267,7 @@ where T2: HashStable, T3: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -291,7 +291,7 @@ where T3: HashStable, T4: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; _0.hash_stable(hcx, hasher); _1.hash_stable(hcx, hasher); @@ -312,7 +312,7 @@ impl StableOrd for ( } impl, Hcx> HashStable for [T] { - default fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + default fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for item in self { item.hash_stable(hcx, hasher); @@ -321,7 +321,7 @@ impl, Hcx> HashStable for [T] { } impl HashStable for [u8] { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); hasher.write(self); } @@ -329,7 +329,7 @@ impl HashStable for [u8] { impl, Hcx> HashStable for Vec { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } @@ -341,7 +341,7 @@ where R: BuildHasher, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for kv in self { kv.hash_stable(hcx, hasher); @@ -355,7 +355,7 @@ where R: BuildHasher, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for key in self { key.hash_stable(hcx, hasher); @@ -368,35 +368,35 @@ where A: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } impl, Hcx> HashStable for Box { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } impl, Hcx> HashStable for ::std::rc::Rc { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } impl, Hcx> HashStable for ::std::sync::Arc { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } impl HashStable for str { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.as_bytes().hash_stable(hcx, hasher); } } @@ -411,7 +411,7 @@ impl StableOrd for &str { impl HashStable for String { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } @@ -442,7 +442,7 @@ impl, T2: ToStableHashKey> ToStableHashKey HashStable for bool { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (if *self { 1u8 } else { 0u8 }).hash_stable(hcx, hasher); } } @@ -459,7 +459,7 @@ where T: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { if let Some(ref value) = *self { 1u8.hash_stable(hcx, hasher); value.hash_stable(hcx, hasher); @@ -482,7 +482,7 @@ where T2: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { Ok(ref x) => x.hash_stable(hcx, hasher), @@ -496,14 +496,14 @@ where T: HashStable + ?Sized, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } impl HashStable for ::std::mem::Discriminant { #[inline] - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -513,7 +513,7 @@ where T: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.start().hash_stable(hcx, hasher); self.end().hash_stable(hcx, hasher); } @@ -523,7 +523,7 @@ impl HashStable for IndexSlice where T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for v in &self.raw { v.hash_stable(hcx, hasher); @@ -535,7 +535,7 @@ impl HashStable for IndexVec where T: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for v in &self.raw { v.hash_stable(hcx, hasher); @@ -544,13 +544,13 @@ where } impl HashStable for DenseBitSet { - fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &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) { + fn hash_stable(&self, _hcx: &Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -571,7 +571,7 @@ where K: HashStable + StableOrd, V: HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); @@ -583,7 +583,7 @@ impl HashStable for ::std::collections::BTreeSet where K: HashStable + StableOrd, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..495472fd0151f 100644 --- a/compiler/rustc_data_structures/src/stable_hasher/tests.rs +++ b/compiler/rustc_data_structures/src/stable_hasher/tests.rs @@ -45,7 +45,7 @@ fn test_attribute_permutation() { } impl HashStable for Foo { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..f65a3f07499e3 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -72,7 +72,7 @@ impl Steal { } impl> HashStable for Steal { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..3d17235ebf232 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -267,7 +267,7 @@ where P: HashStable + Aligned + ?Sized, T: Tag + HashStable, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..658104adbe88f 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs @@ -33,7 +33,7 @@ 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) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut crate::stable_hasher::StableHasher) { (*self as u8).hash_stable(hcx, hasher); } } @@ -65,13 +65,13 @@ fn smoke() { fn stable_hash_hashes_as_tuple() { let hash_packed = { let mut hasher = StableHasher::new(); - TaggedRef::new(&12, Tag2::B11).hash_stable(&mut (), &mut hasher); + TaggedRef::new(&12, Tag2::B11).hash_stable(&(), &mut hasher); hasher.finish::() }; let hash_tupled = { let mut hasher = StableHasher::new(); - (&12, Tag2::B11).hash_stable(&mut (), &mut hasher); + (&12, Tag2::B11).hash_stable(&(), &mut hasher); hasher.finish::() }; diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 8a3b3e2e98cd5..f6a635fc4bdc8 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -417,7 +417,7 @@ impl> From> for UnordSet impl> HashStable for UnordSet { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -640,7 +640,7 @@ where impl, V: HashStable> HashStable for UnordMap { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -703,7 +703,7 @@ impl> From> for UnordBag { impl> HashStable for UnordBag { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -735,7 +735,7 @@ fn hash_iter_order_independent< I: Iterator + ExactSizeIterator, >( mut it: I, - hcx: &mut Hcx, + hcx: &Hcx, hasher: &mut StableHasher, ) { let len = it.len(); diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index c144f0b7dbc5b..6ad9741f10dd9 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -145,7 +145,7 @@ macro_rules! language_item_table { } impl HashStable for LangItem { - fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &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 58649a694880b..93528af6ff5f2 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -67,7 +67,7 @@ impl ToStableHashKey for ForeignItemId // in "DefPath Mode". impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<'tcx> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &HirCtx, 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 @@ -79,14 +79,14 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<' } impl HashStable for DelayedLints { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &HirCtx, 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) { + fn hash_stable(&self, hcx: &HirCtx, 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; @@ -95,7 +95,7 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for AttributeMap } impl HashStable for HashIgnoredAttrId { - fn hash_stable(&self, _hcx: &mut HirCtx, _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &HirCtx, _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..92f0d0a206719 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -56,7 +56,7 @@ impl rustc_index::Idx for OwnerId { impl HashStable for OwnerId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_index_macros/src/newtype.rs b/compiler/rustc_index_macros/src/newtype.rs index b6ee283e736c4..9bccfe7699c20 100644 --- a/compiler/rustc_index_macros/src/newtype.rs +++ b/compiler/rustc_index_macros/src/newtype.rs @@ -166,7 +166,11 @@ impl Parse for Newtype { 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) { + fn hash_stable( + &self, + hcx: &::rustc_middle::ich::StableHashingContext<'__ctx>, + hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher + ) { self.as_u32().hash_stable(hcx, hasher) } } @@ -175,7 +179,11 @@ impl Parse for Newtype { 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) { + fn hash_stable( + &self, + hcx: &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 af1d1854fa5a0..ccdca0f1c13cb 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -140,7 +140,7 @@ impl LintExpectationId { impl HashStable for LintExpectationId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { match self { LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { hir_id.hash_stable(hcx, hasher); @@ -623,7 +623,7 @@ impl LintId { impl HashStable for LintId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.lint_name_raw().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index fa67adb406ed2..2099b61cd7dff 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -111,7 +111,7 @@ fn hash_stable_derive_with_mode( #[inline] fn hash_stable( &self, - __hcx: &mut #context, + __hcx: &#context, __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { #discriminant match *self { #body } 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 10e785ac6b870..6e8d2fd959365 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node_key.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node_key.rs @@ -41,9 +41,9 @@ where #[inline(always)] default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { - tcx.with_stable_hashing_context(|mut hcx| { + tcx.with_stable_hashing_context(|hcx| { let mut hasher = StableHasher::new(); - self.hash_stable(&mut hcx, &mut hasher); + self.hash_stable(&hcx, &mut hasher); hasher.finish() }) } diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index 4e789d702ce03..a897db921a46f 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 { debug_loaded_from_disk: Lock>, } -pub fn hash_result(hcx: &mut StableHashingContext<'_>, result: &R) -> Fingerprint +pub fn hash_result(hcx: &StableHashingContext<'_>, result: &R) -> Fingerprint where R: for<'a> HashStable>, { @@ -283,7 +283,7 @@ impl DepGraph { tcx: TyCtxt<'tcx>, task_arg: A, task_fn: fn(tcx: TyCtxt<'tcx>, task_arg: A) -> R, - hash_result: Option, &R) -> Fingerprint>, + hash_result: Option, &R) -> Fingerprint>, ) -> (R, DepNodeIndex) { match self.data() { Some(data) => data.with_task(dep_node, tcx, task_arg, task_fn, hash_result), @@ -334,7 +334,7 @@ impl DepGraphData { tcx: TyCtxt<'tcx>, task_arg: A, task_fn: fn(tcx: TyCtxt<'tcx>, task_arg: A) -> R, - hash_result: Option, &R) -> Fingerprint>, + hash_result: Option, &R) -> Fingerprint>, ) -> (R, DepNodeIndex) { // If the following assertion triggers, it can have two reasons: // 1. Something is wrong with DepNode creation, either here or @@ -452,12 +452,11 @@ impl DepGraphData { node: DepNode, edges: EdgesVec, result: &R, - hash_result: Option, &R) -> Fingerprint>, + hash_result: Option, &R) -> Fingerprint>, ) -> DepNodeIndex { let hashing_timer = tcx.prof.incr_result_hashing(); - let current_fingerprint = hash_result.map(|hash_result| { - tcx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result)) - }); + let current_fingerprint = hash_result + .map(|hash_result| tcx.with_stable_hashing_context(|hcx| hash_result(&hcx, result))); let dep_node_index = self.alloc_and_color_node(node, edges, current_fingerprint); hashing_timer.finish_with_query_invocation_id(dep_node_index.into()); dep_node_index @@ -577,7 +576,7 @@ impl DepGraph { node: DepNode, tcx: TyCtxt<'tcx>, result: &R, - hash_result: Option, &R) -> Fingerprint>, + hash_result: Option, &R) -> Fingerprint>, format_value_fn: fn(&R) -> String, ) -> DepNodeIndex { if let Some(data) = self.data.as_ref() { diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 499c6dae060bf..13b518320c45c 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -1161,12 +1161,12 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh { .map(DebuggerVisualizerFile::path_erased) .collect(); - let crate_hash: Fingerprint = tcx.with_stable_hashing_context(|mut hcx| { + let crate_hash: Fingerprint = tcx.with_stable_hashing_context(|hcx| { let mut stable_hasher = StableHasher::new(); - hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher); - upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); - source_file_names.hash_stable(&mut hcx, &mut stable_hasher); - debugger_visualizers.hash_stable(&mut hcx, &mut stable_hasher); + hir_body_hash.hash_stable(&hcx, &mut stable_hasher); + upstream_crates.hash_stable(&hcx, &mut stable_hasher); + source_file_names.hash_stable(&hcx, &mut stable_hasher); + debugger_visualizers.hash_stable(&hcx, &mut stable_hasher); if tcx.sess.opts.incremental.is_some() { let definitions = tcx.untracked().definitions.freeze(); let mut owner_spans: Vec<_> = tcx @@ -1180,17 +1180,17 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh { }) .collect(); owner_spans.sort_unstable_by_key(|bn| bn.0); - owner_spans.hash_stable(&mut hcx, &mut stable_hasher); + owner_spans.hash_stable(&hcx, &mut stable_hasher); } - tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher); - tcx.stable_crate_id(LOCAL_CRATE).hash_stable(&mut hcx, &mut stable_hasher); + tcx.sess.opts.dep_tracking_hash(true).hash_stable(&hcx, &mut stable_hasher); + tcx.stable_crate_id(LOCAL_CRATE).hash_stable(&hcx, &mut stable_hasher); // Hash visibility information since it does not appear in HIR. // FIXME: Figure out how to remove `visibilities_for_hashing` by hashing visibilities on // the fly in the resolver, storing only their accumulated hash in `ResolverGlobalCtxt`, // and combining it with other hashes here. - resolutions.visibilities_for_hashing.hash_stable(&mut hcx, &mut stable_hasher); + resolutions.visibilities_for_hashing.hash_stable(&hcx, &mut stable_hasher); with_metavar_spans(|mspans| { - mspans.freeze_and_get_read_spans().hash_stable(&mut hcx, &mut stable_hasher); + mspans.freeze_and_get_read_spans().hash_stable(&hcx, &mut stable_hasher); }); stable_hasher.finish() }); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ad56e462d2934..07075625164e1 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -78,7 +78,7 @@ impl<'hir> Crate<'hir> { } impl HashStable for Crate<'_> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &HirCtx, hasher: &mut StableHasher) { let Crate { opt_hir_hash, .. } = self; opt_hir_hash.unwrap().hash_stable(hcx, hasher) } @@ -247,24 +247,24 @@ impl<'tcx> TyCtxt<'tcx> { }; } - self.with_stable_hashing_context(|mut hcx| { + self.with_stable_hashing_context(|hcx| { let mut stable_hasher = StableHasher::new(); - node.hash_stable(&mut hcx, &mut stable_hasher); + node.hash_stable(&hcx, &mut stable_hasher); // Bodies are stored out of line, so we need to pull them explicitly in the hash. - bodies.hash_stable(&mut hcx, &mut stable_hasher); + bodies.hash_stable(&hcx, &mut stable_hasher); let h1 = stable_hasher.finish(); let mut stable_hasher = StableHasher::new(); - attrs.hash_stable(&mut hcx, &mut stable_hasher); + attrs.hash_stable(&hcx, &mut stable_hasher); // Hash the defined opaque types, which are not present in the attrs. - define_opaque.hash_stable(&mut hcx, &mut stable_hasher); + define_opaque.hash_stable(&hcx, &mut stable_hasher); let h2 = stable_hasher.finish(); // hash lints emitted during ast lowering let mut stable_hasher = StableHasher::new(); - delayed_lints.hash_stable(&mut hcx, &mut stable_hasher); + delayed_lints.hash_stable(&hcx, &mut stable_hasher); let h3 = stable_hasher.finish(); Hashes { diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index d0491aad45317..e25790e6ce790 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -92,7 +92,7 @@ impl<'a> rustc_span::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(&self, span: Span, hasher: &mut StableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; const TAG_RELATIVE_SPAN: u8 = 2; diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index 1063b37be87e8..c6925a1a55fe6 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -11,13 +11,13 @@ use super::StableHashingContext; impl<'a> HashStable> for ast::NodeId { #[inline] - fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { + fn hash_stable(&self, _: &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) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, hasher: &mut StableHasher) { if self.is_empty() { self.len().hash_stable(hcx, hasher); return; @@ -55,7 +55,7 @@ fn is_ignored_attr(name: Symbol) -> bool { } impl<'a> HashStable> for SourceFile { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, hasher: &mut StableHasher) { let SourceFile { name: _, // We hash the smaller stable_id instead of this stable_id, @@ -105,7 +105,7 @@ impl<'a> HashStable> for SourceFile { } impl<'tcx> HashStable> for rustc_feature::Features { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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); @@ -114,7 +114,7 @@ impl<'tcx> HashStable> for rustc_feature::Features { } impl<'tcx> HashStable> for rustc_feature::EnabledLangFeature { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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); @@ -123,7 +123,7 @@ impl<'tcx> HashStable> for rustc_feature::EnabledLang } impl<'tcx> HashStable> for rustc_feature::EnabledLibFeature { - fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 0be4c8243d632..ef8e70229a0e8 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -274,7 +274,7 @@ impl Default for EffectiveVisibilities { } impl<'a> HashStable> for EffectiveVisibilities { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, 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..99bdd3dbad3c1 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -173,5 +173,5 @@ impl Decodable for Cache { impl HashStable for Cache { #[inline] - fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {} + fn hash_stable(&self, _: &Hcx, _: &mut StableHasher) {} } diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index acebf91b1cbf5..b093a535e075f 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -330,7 +330,7 @@ impl ToStableHashKey> for MonoItem<'_> { fn to_stable_hash_key(&self, hcx: &StableHashingContext<'_>) -> Self::KeyType { let mut hasher = StableHasher::new(); - self.hash_stable(&mut hcx.clone(), &mut hasher); + self.hash_stable(&hcx.clone(), &mut hasher); hasher.finish() } } diff --git a/compiler/rustc_middle/src/query/inner.rs b/compiler/rustc_middle/src/query/inner.rs index 402c448a1fa3a..c6578fb3bcfe6 100644 --- a/compiler/rustc_middle/src/query/inner.rs +++ b/compiler/rustc_middle/src/query/inner.rs @@ -128,8 +128,8 @@ pub(crate) fn query_feed<'tcx, C>( // That's OK if both values are the same, i.e. they have the same hash, // so now we check their hashes. if let Some(hash_value_fn) = query.hash_value_fn { - let (old_hash, value_hash) = tcx.with_stable_hashing_context(|ref mut hcx| { - (hash_value_fn(hcx, &old), hash_value_fn(hcx, &value)) + let (old_hash, value_hash) = tcx.with_stable_hashing_context(|hcx| { + (hash_value_fn(&hcx, &old), hash_value_fn(&hcx, &value)) }); if old_hash != value_hash { // We have an inconsistency. This can happen if one of the two diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 4dbceba924036..7247ec933db10 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -582,9 +582,9 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> { #[cfg(debug_assertions)] { use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; - let local_hash = self.tcx.with_stable_hashing_context(|mut hcx| { + let local_hash = self.tcx.with_stable_hashing_context(|hcx| { let mut hasher = StableHasher::new(); - expn_id.expn_data().hash_stable(&mut hcx, &mut hasher); + expn_id.expn_data().hash_stable(&hcx, &mut hasher); hasher.finish() }); debug_assert_eq!(hash.local_hash(), local_hash); diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 2e1e614b8fb4c..4461f44eae84e 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -109,7 +109,7 @@ pub struct QueryVTable<'tcx, C: QueryCache> { /// Function pointer that hashes this query's result values. /// /// For `no_hash` queries, this function pointer is None. - pub hash_value_fn: Option, &C::Value) -> Fingerprint>, + pub hash_value_fn: Option, &C::Value) -> Fingerprint>, /// Function pointer that handles a cycle error. `error` must be consumed, e.g. with `emit` (if /// it should be emitted) or `delay_as_bug` (if it need not be emitted because an alternative diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index ae3c45877900b..2c9e8d6eaf154 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -152,7 +152,7 @@ impl Hash for AdtDefData { } impl<'a> HashStable> for AdtDefData { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, 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..3842c60336801 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -152,7 +152,7 @@ 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) { + fn hash_stable(&self, hcx: &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 a81697cc96dbb..3211f53bb8cd0 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -264,8 +264,8 @@ impl<'tcx> CtxtInterners<'tcx> { Fingerprint::ZERO } else { let mut hasher = StableHasher::new(); - let mut hcx = StableHashingContext::new(sess, untracked); - val.hash_stable(&mut hcx, &mut hasher); + let hcx = StableHashingContext::new(sess, untracked); + val.hash_stable(&hcx, &mut hasher); hasher.finish() } } diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index f06ce7324d4c0..a181d2a245402 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -19,7 +19,7 @@ impl<'a, 'tcx, H, T> HashStable> for &'tcx ty::list::Ra where T: HashStable>, { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, 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(!) @@ -55,21 +55,21 @@ where #[inline] fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint { let mut hasher = StableHasher::new(); - let mut hcx: StableHashingContext<'a> = hcx.clone(); - self.hash_stable(&mut hcx, &mut hasher); + let hcx: StableHashingContext<'a> = hcx.clone(); + 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) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, 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) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, hasher: &mut StableHasher) { ty::tls::with_opt(|tcx| { trace!("hashing {:?}", *self); let tcx = tcx.expect("can't hash AllocIds during hir lowering"); @@ -79,7 +79,7 @@ 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) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, hasher: &mut StableHasher) { self.into_parts().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 822bbe079327f..f8956f2b167f7 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -512,7 +512,7 @@ impl<'tcx> From> for Term<'tcx> { } impl<'a, 'tcx> HashStable> for Term<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &StableHashingContext<'a>, hasher: &mut StableHasher) { self.kind().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_middle/src/verify_ich.rs b/compiler/rustc_middle/src/verify_ich.rs index a1ab4d8cc4d00..8b573109d2598 100644 --- a/compiler/rustc_middle/src/verify_ich.rs +++ b/compiler/rustc_middle/src/verify_ich.rs @@ -14,16 +14,15 @@ pub fn incremental_verify_ich<'tcx, V>( dep_graph_data: &DepGraphData, result: &V, prev_index: SerializedDepNodeIndex, - hash_result: Option, &V) -> Fingerprint>, + hash_result: Option, &V) -> Fingerprint>, format_value: fn(&V) -> String, ) { if !dep_graph_data.is_index_green(prev_index) { incremental_verify_ich_not_green(tcx, prev_index) } - let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| { - tcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result)) - }); + let new_hash = hash_result + .map_or(Fingerprint::ZERO, |f| tcx.with_stable_hashing_context(|hcx| f(&hcx, result))); let old_hash = dep_graph_data.prev_value_fingerprint_of(prev_index); diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 44995f3f9826a..6b3f3f216a693 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -361,8 +361,8 @@ fn check_feedable_consistency<'tcx, C: QueryCache>( ); }; - let (old_hash, new_hash) = tcx.with_stable_hashing_context(|mut hcx| { - (hash_value_fn(&mut hcx, &cached_value), hash_value_fn(&mut hcx, value)) + let (old_hash, new_hash) = tcx.with_stable_hashing_context(|hcx| { + (hash_value_fn(&hcx, &cached_value), hash_value_fn(&hcx, value)) }); let formatter = query.format_value; if old_hash != new_hash { @@ -400,8 +400,8 @@ fn execute_job_non_incr<'tcx, C: QueryCache>( if cfg!(debug_assertions) { let _ = key.to_fingerprint(tcx); if let Some(hash_value_fn) = query.hash_value_fn { - tcx.with_stable_hashing_context(|mut hcx| { - hash_value_fn(&mut hcx, &value); + tcx.with_stable_hashing_context(|hcx| { + hash_value_fn(&hcx, &value); }); } } diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 8c313c7f8b3a3..13e317d0d5b2d 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -404,21 +404,21 @@ rustc_data_structures::define_id_collections!( impl HashStable for DefId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { hcx.def_path_hash(*self).hash_stable(hcx, hasher); } } impl HashStable for LocalDefId { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { hcx.def_path_hash(self.to_def_id()).local_hash().hash_stable(hcx, hasher); } } impl HashStable for CrateNum { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.as_def_id().to_stable_hash_key(hcx).stable_crate_id().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index e7b98cc910973..e80032582b061 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -1102,7 +1102,7 @@ impl ExpnData { } #[inline] - fn hash_expn(&self, hcx: &mut impl HashStableContext) -> Hash64 { + fn hash_expn(&self, hcx: &impl HashStableContext) -> Hash64 { let mut hasher = StableHasher::new(); self.hash_stable(hcx, &mut hasher); hasher.finish() @@ -1482,11 +1482,11 @@ pub fn raw_encode_syntax_context( /// `set_expn_data`). It is *not* called for foreign `ExpnId`s deserialized /// from another crate's metadata - since `ExpnHash` includes the stable crate id, /// collisions are only possible between `ExpnId`s within the same crate. -fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContext) -> ExpnHash { +fn update_disambiguator(expn_data: &mut ExpnData, hcx: impl HashStableContext) -> ExpnHash { // This disambiguator should not have been set yet. assert_eq!(expn_data.disambiguator, 0, "Already set disambiguator for ExpnData: {expn_data:?}"); hcx.assert_default_hashing_controls("ExpnData (disambiguator)"); - let mut expn_hash = expn_data.hash_expn(&mut hcx); + let mut expn_hash = expn_data.hash_expn(&hcx); let disambiguator = HygieneData::with(|data| { // If this is the first ExpnData with a given hash, then keep our @@ -1501,7 +1501,7 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContex debug!("Set disambiguator for expn_data={:?} expn_hash={:?}", expn_data, expn_hash); expn_data.disambiguator = disambiguator; - expn_hash = expn_data.hash_expn(&mut hcx); + expn_hash = expn_data.hash_expn(&hcx); // Verify that the new disambiguator makes the hash unique #[cfg(debug_assertions)] @@ -1518,7 +1518,7 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContex } impl HashStable for SyntaxContext { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { const TAG_EXPANSION: u8 = 0; const TAG_NO_EXPANSION: u8 = 1; @@ -1534,7 +1534,7 @@ impl HashStable for SyntaxContext { } impl HashStable for ExpnId { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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. @@ -1548,7 +1548,7 @@ impl HashStable for ExpnId { } impl HashStable for LocalExpnId { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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 6794ffb311e32..164fe96e40372 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2802,7 +2802,7 @@ impl InnerSpan { /// instead of implementing everything in rustc_middle. pub trait HashStableContext { /// The main event: stable hashing of a span. - fn span_hash_stable(&mut self, span: Span, hasher: &mut StableHasher); + fn span_hash_stable(&self, span: Span, hasher: &mut StableHasher); /// Compute a `DefPathHash`. fn def_path_hash(&self, def_id: DefId) -> DefPathHash; @@ -2816,7 +2816,7 @@ impl HashStable for Span where Hcx: HashStableContext, { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { // `span_hash_stable` does all the work. hcx.span_hash_stable(*self, hasher) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 30bf8dd7c2206..57be91fff7614 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2603,7 +2603,7 @@ impl fmt::Display for Symbol { impl HashStable for Symbol { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.as_str().hash_stable(hcx, hasher); } } @@ -2663,7 +2663,7 @@ impl fmt::Debug for ByteSymbol { impl HashStable for ByteSymbol { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { self.as_byte_str().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_symbol_mangling/src/hashed.rs b/compiler/rustc_symbol_mangling/src/hashed.rs index e965e6a7d53aa..1b6eef5ab5a99 100644 --- a/compiler/rustc_symbol_mangling/src/hashed.rs +++ b/compiler/rustc_symbol_mangling/src/hashed.rs @@ -25,9 +25,9 @@ pub(super) fn mangle<'tcx>( let mut symbol = "_RNxC".to_string(); v0::push_ident(tcx.crate_name(crate_num).as_str(), &mut symbol); - let hash = tcx.with_stable_hashing_context(|mut hcx| { + let hash = tcx.with_stable_hashing_context(|hcx| { let mut hasher = StableHasher::new(); - full_mangling_name().hash_stable(&mut hcx, &mut hasher); + full_mangling_name().hash_stable(&hcx, &mut hasher); hasher.finish::().as_u64() }); diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 54ecf277cd3df..f6c3bc7690814 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -135,7 +135,7 @@ fn get_symbol_hash<'tcx>( // the main symbol name is not necessarily unique; hash in the // compiler's internal def-path, guaranteeing each symbol has a // truly unique path - tcx.def_path_hash(def_id).hash_stable(&mut hcx, &mut hasher); + tcx.def_path_hash(def_id).hash_stable(&hcx, &mut hasher); // Include the main item-type. Note that, in this case, the // assertions about `has_param` may not hold, but this item-type diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 9786608ab4bc0..9f50f27f75870 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -118,7 +118,7 @@ impl fmt::Debug for InferConst { #[cfg(feature = "nightly")] impl HashStable for InferConst { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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 6bd985a20ae01..3f43b45f7b17c 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -56,8 +56,8 @@ impl> ToStableHashKey for SimplifiedType #[inline] fn to_stable_hash_key(&self, hcx: &Hcx) -> Fingerprint { let mut hasher = StableHasher::new(); - let mut hcx: Hcx = hcx.clone(); - self.hash_stable(&mut hcx, &mut hasher); + let hcx: Hcx = hcx.clone(); + self.hash_stable(&hcx, &mut hasher); hasher.finish() } } diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index d1076be20bae2..e21bd687de143 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -225,7 +225,7 @@ where I::Symbol: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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..691f7b09f7575 100644 --- a/compiler/rustc_type_ir/src/ty_info.rs +++ b/compiler/rustc_type_ir/src/ty_info.rs @@ -98,7 +98,7 @@ impl Hash for WithCachedTypeInfo { #[cfg(feature = "nightly")] impl, Hcx> HashStable for WithCachedTypeInfo { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &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 ad7a934bb28a5..d7f10012d2153 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -688,7 +688,7 @@ impl UnifyKey for FloatVid { #[cfg(feature = "nightly")] impl HashStable for InferTy { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &Hcx, hasher: &mut StableHasher) { use InferTy::*; std::mem::discriminant(self).hash_stable(hcx, hasher); match self { From 79b99e682951737086a811a8a725c520c2ccceaa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Apr 2026 07:52:07 +1100 Subject: [PATCH 3/3] Avoid cloning of `StableHashingContext`. It's no longer needed now that `hash_stable` takes a `&hcx` instead of `&mut hcx`. --- compiler/rustc_middle/src/ich/hcx.rs | 2 -- compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/ty/impls_ty.rs | 3 +-- compiler/rustc_span/src/caching_source_map_view.rs | 1 - compiler/rustc_type_ir/src/fast_reject.rs | 5 ++--- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index e25790e6ce790..6996f3068a883 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -11,7 +11,6 @@ use rustc_span::{BytePos, CachingSourceMapView, DUMMY_SP, Pos, SourceFile, Span, // Very often, we are hashing something that does not need the `CachingSourceMapView`, so we // initialize it lazily. -#[derive(Clone)] enum CachingSourceMap<'a> { Unused(&'a Session), InUse(CachingSourceMapView<'a>), @@ -21,7 +20,6 @@ enum CachingSourceMap<'a> { /// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e., /// a reference to the `TyCtxt`) and it holds a few caches for speeding up various /// things (e.g., each `DefId`/`DefPath` is only hashed once). -#[derive(Clone)] pub struct StableHashingContext<'a> { untracked: &'a Untracked, // The value of `-Z incremental-ignore-spans`. diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index b093a535e075f..e6f68fd3be08c 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -330,7 +330,7 @@ impl ToStableHashKey> for MonoItem<'_> { fn to_stable_hash_key(&self, hcx: &StableHashingContext<'_>) -> Self::KeyType { let mut hasher = StableHasher::new(); - self.hash_stable(&hcx.clone(), &mut hasher); + self.hash_stable(hcx, &mut hasher); hasher.finish() } } diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index a181d2a245402..2e700f88aa231 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -55,8 +55,7 @@ where #[inline] fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint { let mut hasher = StableHasher::new(); - let hcx: StableHashingContext<'a> = hcx.clone(); - self.hash_stable(&hcx, &mut hasher); + self.hash_stable(hcx, &mut hasher); hasher.finish() } } diff --git a/compiler/rustc_span/src/caching_source_map_view.rs b/compiler/rustc_span/src/caching_source_map_view.rs index 297d65fd5c273..39125800757c5 100644 --- a/compiler/rustc_span/src/caching_source_map_view.rs +++ b/compiler/rustc_span/src/caching_source_map_view.rs @@ -9,7 +9,6 @@ use crate::{BytePos, Pos, RelativeBytePos, SourceFile, SpanData}; /// succession, and this avoids expensive `SourceMap` lookups each time the cache is hit. We used /// to cache multiple code positions, but caching a single position ended up being simpler and /// faster. -#[derive(Clone)] pub struct CachingSourceMapView<'sm> { source_map: &'sm SourceMap, file: Arc, diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index 3f43b45f7b17c..bdbc467657984 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -50,14 +50,13 @@ 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: &Hcx) -> Fingerprint { let mut hasher = StableHasher::new(); - let hcx: Hcx = hcx.clone(); - self.hash_stable(&hcx, &mut hasher); + self.hash_stable(hcx, &mut hasher); hasher.finish() } }