Remove Clone impl for StableHashingContext.

`HashStable::hash_stable` takes a `&mut Hcx`. In contrast,
`ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are
some places where the latter calls the former, and due to the mismatch a
`clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`.
This eliminates the mismatch, the need for the clones, and the need for
the `Clone` impls.
This commit is contained in:
Nicholas Nethercote
2026-04-02 16:06:59 +11:00
parent 55e86c9968
commit ff1795fe49
21 changed files with 59 additions and 59 deletions
@@ -175,8 +175,8 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
// FIXME: Sorting this is unnecessary since we are sorting later anyway. // FIXME: Sorting this is unnecessary since we are sorting later anyway.
// Can we skip the later sorting? // Can we skip the later sorting?
let sorted = tcx.with_stable_hashing_context(|hcx| { let sorted = tcx.with_stable_hashing_context(|mut hcx| {
tcx.reachable_non_generics(LOCAL_CRATE).to_sorted(&hcx, true) tcx.reachable_non_generics(LOCAL_CRATE).to_sorted(&mut hcx, true)
}); });
let mut symbols: Vec<_> = let mut symbols: Vec<_> =
@@ -50,7 +50,7 @@ pub trait HashStable<Hcx> {
/// bringing maps into a predictable order before hashing them. /// bringing maps into a predictable order before hashing them.
pub trait ToStableHashKey<Hcx> { pub trait ToStableHashKey<Hcx> {
type KeyType: Ord + Sized + HashStable<Hcx>; type KeyType: Ord + Sized + HashStable<Hcx>;
fn to_stable_hash_key(&self, hcx: &Hcx) -> Self::KeyType; fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType;
} }
/// Trait for marking a type as having a sort order that is /// Trait for marking a type as having a sort order that is
@@ -427,7 +427,7 @@ impl StableOrd for String {
impl<Hcx> ToStableHashKey<Hcx> for String { impl<Hcx> ToStableHashKey<Hcx> for String {
type KeyType = String; type KeyType = String;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
self.clone() self.clone()
} }
} }
@@ -435,7 +435,7 @@ fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType {
impl<Hcx, T1: ToStableHashKey<Hcx>, T2: ToStableHashKey<Hcx>> ToStableHashKey<Hcx> for (T1, T2) { impl<Hcx, T1: ToStableHashKey<Hcx>, T2: ToStableHashKey<Hcx>> ToStableHashKey<Hcx> for (T1, T2) {
type KeyType = (T1::KeyType, T2::KeyType); type KeyType = (T1::KeyType, T2::KeyType);
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &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)) (self.0.to_stable_hash_key(hcx), self.1.to_stable_hash_key(hcx))
} }
} }
+12 -8
View File
@@ -143,7 +143,7 @@ pub fn copied(self) -> UnordItems<T, impl Iterator<Item = T>> {
impl<T, I: Iterator<Item = T>> UnordItems<T, I> { impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
#[inline] #[inline]
pub fn into_sorted<Hcx>(self, hcx: &Hcx) -> Vec<T> pub fn into_sorted<Hcx>(self, hcx: &mut Hcx) -> Vec<T>
where where
T: ToStableHashKey<Hcx>, T: ToStableHashKey<Hcx>,
{ {
@@ -168,7 +168,7 @@ pub fn into_sorted_stable_ord_by_key<K, C>(self, project_to_key: C) -> Vec<T>
} }
#[inline] #[inline]
pub fn collect_sorted<Hcx, C>(self, hcx: &Hcx, cache_sort_key: bool) -> C pub fn collect_sorted<Hcx, C>(self, hcx: &mut Hcx, cache_sort_key: bool) -> C
where where
T: ToStableHashKey<Hcx>, T: ToStableHashKey<Hcx>,
C: FromIterator<T> + BorrowMut<[T]>, C: FromIterator<T> + BorrowMut<[T]>,
@@ -315,7 +315,7 @@ pub fn into_items(self) -> UnordItems<V, impl Iterator<Item = V>> {
/// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation
/// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup). /// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup).
#[inline] #[inline]
pub fn to_sorted<Hcx>(&self, hcx: &Hcx, cache_sort_key: bool) -> Vec<&V> pub fn to_sorted<Hcx>(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<&V>
where where
V: ToStableHashKey<Hcx>, V: ToStableHashKey<Hcx>,
{ {
@@ -357,7 +357,7 @@ pub fn into_sorted_stable_ord(self) -> Vec<V>
/// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation
/// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup). /// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup).
#[inline] #[inline]
pub fn into_sorted<Hcx>(self, hcx: &Hcx, cache_sort_key: bool) -> Vec<V> pub fn into_sorted<Hcx>(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<V>
where where
V: ToStableHashKey<Hcx>, V: ToStableHashKey<Hcx>,
{ {
@@ -555,7 +555,7 @@ pub fn keys(&self) -> UnordItems<&K, impl Iterator<Item = &K>> {
/// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation
/// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup).
#[inline] #[inline]
pub fn to_sorted<Hcx>(&self, hcx: &Hcx, cache_sort_key: bool) -> Vec<(&K, &V)> pub fn to_sorted<Hcx>(&self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(&K, &V)>
where where
K: ToStableHashKey<Hcx>, K: ToStableHashKey<Hcx>,
{ {
@@ -582,7 +582,7 @@ pub fn to_sorted_stable_ord(&self) -> Vec<(&K, &V)>
/// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation
/// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup).
#[inline] #[inline]
pub fn into_sorted<Hcx>(self, hcx: &Hcx, cache_sort_key: bool) -> Vec<(K, V)> pub fn into_sorted<Hcx>(self, hcx: &mut Hcx, cache_sort_key: bool) -> Vec<(K, V)>
where where
K: ToStableHashKey<Hcx>, K: ToStableHashKey<Hcx>,
{ {
@@ -610,7 +610,11 @@ pub fn into_sorted_stable_ord(self) -> Vec<(K, V)>
/// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation
/// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup).
#[inline] #[inline]
pub fn values_sorted<Hcx>(&self, hcx: &Hcx, cache_sort_key: bool) -> impl Iterator<Item = &V> pub fn values_sorted<Hcx>(
&self,
hcx: &mut Hcx,
cache_sort_key: bool,
) -> impl Iterator<Item = &V>
where where
K: ToStableHashKey<Hcx>, K: ToStableHashKey<Hcx>,
{ {
@@ -710,7 +714,7 @@ fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
#[inline] #[inline]
fn to_sorted_vec<Hcx, T, K, I>( fn to_sorted_vec<Hcx, T, K, I>(
hcx: &Hcx, hcx: &mut Hcx,
iter: I, iter: I,
cache_sort_key: bool, cache_sort_key: bool,
extract_key: fn(&T) -> &K, extract_key: fn(&T) -> &K,
+1 -1
View File
@@ -716,7 +716,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for Namespace {
type KeyType = Namespace; type KeyType = Namespace;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> Namespace { fn to_stable_hash_key(&self, _: &mut Hcx) -> Namespace {
*self *self
} }
} }
+5 -5
View File
@@ -13,7 +13,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
type KeyType = (DefPathHash, ItemLocalId); type KeyType = (DefPathHash, ItemLocalId);
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> (DefPathHash, ItemLocalId) { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) {
let BodyId { hir_id } = *self; let BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx) hir_id.to_stable_hash_key(hcx)
} }
@@ -23,7 +23,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx) self.owner_id.def_id.to_stable_hash_key(hcx)
} }
} }
@@ -32,7 +32,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for TraitItemId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx) self.owner_id.def_id.to_stable_hash_key(hcx)
} }
} }
@@ -41,7 +41,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ImplItemId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx) self.owner_id.def_id.to_stable_hash_key(hcx)
} }
} }
@@ -50,7 +50,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx) self.owner_id.def_id.to_stable_hash_key(hcx)
} }
} }
+3 -3
View File
@@ -65,7 +65,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for OwnerId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
hcx.def_path_hash(self.to_def_id()) hcx.def_path_hash(self.to_def_id())
} }
} }
@@ -180,7 +180,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for HirId {
type KeyType = (DefPathHash, ItemLocalId); type KeyType = (DefPathHash, ItemLocalId);
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &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); let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx);
(def_path_hash, self.local_id) (def_path_hash, self.local_id)
} }
@@ -190,7 +190,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemLocalId {
type KeyType = ItemLocalId; type KeyType = ItemLocalId;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> ItemLocalId { fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId {
*self *self
} }
} }
+6 -6
View File
@@ -375,12 +375,12 @@ fn visit_infer(
impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
fn eval_closure_size(&mut self) { fn eval_closure_size(&mut self) {
self.tcx().with_stable_hashing_context(|ref hcx| { self.tcx().with_stable_hashing_context(|mut hcx| {
let fcx_typeck_results = self.fcx.typeck_results.borrow(); let fcx_typeck_results = self.fcx.typeck_results.borrow();
self.typeck_results.closure_size_eval = fcx_typeck_results self.typeck_results.closure_size_eval = fcx_typeck_results
.closure_size_eval .closure_size_eval
.to_sorted(hcx, false) .to_sorted(&mut hcx, false)
.into_iter() .into_iter()
.map(|(&closure_def_id, data)| { .map(|(&closure_def_id, data)| {
let closure_hir_id = self.tcx().local_def_id_to_hir_id(closure_def_id); let closure_hir_id = self.tcx().local_def_id_to_hir_id(closure_def_id);
@@ -392,12 +392,12 @@ fn eval_closure_size(&mut self) {
} }
fn visit_min_capture_map(&mut self) { fn visit_min_capture_map(&mut self) {
self.tcx().with_stable_hashing_context(|ref hcx| { self.tcx().with_stable_hashing_context(|mut hcx| {
let fcx_typeck_results = self.fcx.typeck_results.borrow(); let fcx_typeck_results = self.fcx.typeck_results.borrow();
self.typeck_results.closure_min_captures = fcx_typeck_results self.typeck_results.closure_min_captures = fcx_typeck_results
.closure_min_captures .closure_min_captures
.to_sorted(hcx, false) .to_sorted(&mut hcx, false)
.into_iter() .into_iter()
.map(|(&closure_def_id, root_min_captures)| { .map(|(&closure_def_id, root_min_captures)| {
let root_var_map_wb = root_min_captures let root_var_map_wb = root_min_captures
@@ -423,12 +423,12 @@ fn visit_min_capture_map(&mut self) {
} }
fn visit_fake_reads_map(&mut self) { fn visit_fake_reads_map(&mut self) {
self.tcx().with_stable_hashing_context(move |ref hcx| { self.tcx().with_stable_hashing_context(move |mut hcx| {
let fcx_typeck_results = self.fcx.typeck_results.borrow(); let fcx_typeck_results = self.fcx.typeck_results.borrow();
self.typeck_results.closure_fake_reads = fcx_typeck_results self.typeck_results.closure_fake_reads = fcx_typeck_results
.closure_fake_reads .closure_fake_reads
.to_sorted(hcx, true) .to_sorted(&mut hcx, true)
.into_iter() .into_iter()
.map(|(&closure_def_id, fake_reads)| { .map(|(&closure_def_id, fake_reads)| {
let resolved_fake_reads = fake_reads let resolved_fake_reads = fake_reads
+2 -2
View File
@@ -160,7 +160,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for LintExpectationId {
type KeyType = (DefPathHash, ItemLocalId, u16, u16); type KeyType = (DefPathHash, ItemLocalId, u16, u16);
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> Self::KeyType { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Self::KeyType {
match self { match self {
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx); let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx);
@@ -632,7 +632,7 @@ impl<Hcx> ToStableHashKey<Hcx> for LintId {
type KeyType = &'static str; type KeyType = &'static str;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> &'static str { fn to_stable_hash_key(&self, _: &mut Hcx) -> &'static str {
self.lint_name_raw() self.lint_name_raw()
} }
} }
@@ -254,7 +254,7 @@ pub fn from_cgu_name(cgu_name: &str) -> WorkProductId {
impl<Hcx> ToStableHashKey<Hcx> for WorkProductId { impl<Hcx> ToStableHashKey<Hcx> for WorkProductId {
type KeyType = Fingerprint; type KeyType = Fingerprint;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
self.hash self.hash
} }
} }
-2
View File
@@ -10,7 +10,6 @@
// Very often, we are hashing something that does not need the `CachingSourceMapView`, so we // Very often, we are hashing something that does not need the `CachingSourceMapView`, so we
// initialize it lazily. // initialize it lazily.
#[derive(Clone)]
enum CachingSourceMap<'a> { enum CachingSourceMap<'a> {
Unused(&'a SourceMap), Unused(&'a SourceMap),
InUse(CachingSourceMapView<'a>), InUse(CachingSourceMapView<'a>),
@@ -20,7 +19,6 @@ enum CachingSourceMap<'a> {
/// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e., /// 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 /// 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). /// things (e.g., each `DefId`/`DefPath` is only hashed once).
#[derive(Clone)]
pub struct StableHashingContext<'a> { pub struct StableHashingContext<'a> {
untracked: &'a Untracked, untracked: &'a Untracked,
// The value of `-Z incremental-ignore-spans`. // The value of `-Z incremental-ignore-spans`.
+3 -3
View File
@@ -328,9 +328,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl ToStableHashKey<StableHashingContext<'_>> for MonoItem<'_> { impl ToStableHashKey<StableHashingContext<'_>> for MonoItem<'_> {
type KeyType = Fingerprint; type KeyType = Fingerprint;
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'_>) -> Self::KeyType { fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'_>) -> Self::KeyType {
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
self.hash_stable(&mut hcx.clone(), &mut hasher); self.hash_stable(hcx, &mut hasher);
hasher.finish() hasher.finish()
} }
} }
@@ -584,7 +584,7 @@ pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
impl ToStableHashKey<StableHashingContext<'_>> for CodegenUnit<'_> { impl ToStableHashKey<StableHashingContext<'_>> for CodegenUnit<'_> {
type KeyType = String; type KeyType = String;
fn to_stable_hash_key(&self, _: &StableHashingContext<'_>) -> Self::KeyType { fn to_stable_hash_key(&self, _: &mut StableHashingContext<'_>) -> Self::KeyType {
// Codegen unit names are conceptually required to be stable across // Codegen unit names are conceptually required to be stable across
// compilation session so that object file names match up. // compilation session so that object file names match up.
self.name.to_string() self.name.to_string()
+3 -4
View File
@@ -53,10 +53,9 @@ impl<'a, 'tcx, H, T> ToStableHashKey<StableHashingContext<'a>> for &'tcx ty::lis
type KeyType = Fingerprint; type KeyType = Fingerprint;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Fingerprint { fn to_stable_hash_key(&self, hcx: &mut StableHashingContext<'a>) -> Fingerprint {
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
let mut hcx: StableHashingContext<'a> = hcx.clone(); self.hash_stable(hcx, &mut hasher);
self.hash_stable(&mut hcx, &mut hasher);
hasher.finish() hasher.finish()
} }
} }
@@ -88,7 +87,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
type KeyType = region::Scope; type KeyType = region::Scope;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> region::Scope { fn to_stable_hash_key(&self, _: &mut StableHashingContext<'a>) -> region::Scope {
*self *self
} }
} }
+2 -2
View File
@@ -1824,8 +1824,8 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
// The set of MonoItems was created in an inherently indeterministic order because // The set of MonoItems was created in an inherently indeterministic order because
// of parallelism. We sort it here to ensure that the output is deterministic. // of parallelism. We sort it here to ensure that the output is deterministic.
let mono_items = tcx.with_stable_hashing_context(move |ref hcx| { let mono_items = tcx.with_stable_hashing_context(move |mut hcx| {
state.visited.into_inner().into_sorted(hcx, true) state.visited.into_inner().into_sorted(&mut hcx, true)
}); });
(mono_items, state.usage_map.into_inner()) (mono_items, state.usage_map.into_inner())
@@ -286,8 +286,8 @@ fn place_mono_items<'tcx, I>(cx: &PartitioningCx<'_, 'tcx>, mono_items: I) -> Pl
codegen_units.insert(cgu_name, CodegenUnit::new(cgu_name)); codegen_units.insert(cgu_name, CodegenUnit::new(cgu_name));
} }
let mut codegen_units: Vec<_> = cx.tcx.with_stable_hashing_context(|ref hcx| { let mut codegen_units: Vec<_> = cx.tcx.with_stable_hashing_context(|mut hcx| {
codegen_units.into_items().map(|(_, cgu)| cgu).collect_sorted(hcx, true) codegen_units.into_items().map(|(_, cgu)| cgu).collect_sorted(&mut hcx, true)
}); });
for cgu in codegen_units.iter_mut() { for cgu in codegen_units.iter_mut() {
@@ -1535,9 +1535,10 @@ fn detect_missing_binding_available_from_pattern(
let [segment] = path else { return }; let [segment] = path else { return };
let None = following_seg else { return }; let None = following_seg else { return };
for rib in self.ribs[ValueNS].iter().rev() { for rib in self.ribs[ValueNS].iter().rev() {
let patterns_with_skipped_bindings = self.r.tcx.with_stable_hashing_context(|hcx| { let patterns_with_skipped_bindings =
rib.patterns_with_skipped_bindings.to_sorted(&hcx, true) self.r.tcx.with_stable_hashing_context(|mut hcx| {
}); rib.patterns_with_skipped_bindings.to_sorted(&mut hcx, true)
});
for (def_id, spans) in patterns_with_skipped_bindings { for (def_id, spans) in patterns_with_skipped_bindings {
if let DefKind::Struct | DefKind::Variant = self.r.tcx.def_kind(*def_id) if let DefKind::Struct | DefKind::Variant = self.r.tcx.def_kind(*def_id)
&& let Some(fields) = self.r.field_idents(*def_id) && let Some(fields) = self.r.field_idents(*def_id)
+1 -1
View File
@@ -640,7 +640,7 @@ impl StableOrd for OutputType {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for OutputType { impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for OutputType {
type KeyType = Self; type KeyType = Self;
fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { fn to_stable_hash_key(&self, _: &mut Hcx) -> Self::KeyType {
*self *self
} }
} }
@@ -9,7 +9,6 @@
/// succession, and this avoids expensive `SourceMap` lookups each time the cache is hit. We used /// 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 /// to cache multiple code positions, but caching a single position ended up being simpler and
/// faster. /// faster.
#[derive(Clone)]
pub struct CachingSourceMapView<'sm> { pub struct CachingSourceMapView<'sm> {
source_map: &'sm SourceMap, source_map: &'sm SourceMap,
file: Arc<SourceFile>, file: Arc<SourceFile>,
+4 -4
View File
@@ -427,7 +427,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for DefId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
hcx.def_path_hash(*self) hcx.def_path_hash(*self)
} }
} }
@@ -436,7 +436,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for LocalDefId {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
hcx.def_path_hash(self.to_def_id()) hcx.def_path_hash(self.to_def_id())
} }
} }
@@ -445,7 +445,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for CrateNum {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash {
self.as_def_id().to_stable_hash_key(hcx) self.as_def_id().to_stable_hash_key(hcx)
} }
} }
@@ -454,7 +454,7 @@ impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for DefPathHash {
type KeyType = DefPathHash; type KeyType = DefPathHash;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> DefPathHash { fn to_stable_hash_key(&self, _: &mut Hcx) -> DefPathHash {
*self *self
} }
} }
+1 -1
View File
@@ -2611,7 +2611,7 @@ fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
impl<Hcx> ToStableHashKey<Hcx> for Symbol { impl<Hcx> ToStableHashKey<Hcx> for Symbol {
type KeyType = String; type KeyType = String;
#[inline] #[inline]
fn to_stable_hash_key(&self, _: &Hcx) -> String { fn to_stable_hash_key(&self, _: &mut Hcx) -> String {
self.as_str().to_string() self.as_str().to_string()
} }
} }
+3 -4
View File
@@ -50,14 +50,13 @@ pub enum SimplifiedType<DefId> {
} }
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
impl<Hcx: Clone, DefId: HashStable<Hcx>> ToStableHashKey<Hcx> for SimplifiedType<DefId> { impl<Hcx, DefId: HashStable<Hcx>> ToStableHashKey<Hcx> for SimplifiedType<DefId> {
type KeyType = Fingerprint; type KeyType = Fingerprint;
#[inline] #[inline]
fn to_stable_hash_key(&self, hcx: &Hcx) -> Fingerprint { fn to_stable_hash_key(&self, hcx: &mut Hcx) -> Fingerprint {
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
let mut hcx: Hcx = hcx.clone(); self.hash_stable(hcx, &mut hasher);
self.hash_stable(&mut hcx, &mut hasher);
hasher.finish() hasher.finish()
} }
} }
+1 -1
View File
@@ -310,7 +310,7 @@ fn config(&mut self, config: &mut Config) {
// FIXME handle this somehow in rustc itself to avoid this hack. // FIXME handle this somehow in rustc itself to avoid this hack.
local_providers.queries.exported_non_generic_symbols = |tcx, LocalCrate| { local_providers.queries.exported_non_generic_symbols = |tcx, LocalCrate| {
let reachable_set = tcx let reachable_set = tcx
.with_stable_hashing_context(|hcx| tcx.reachable_set(()).to_sorted(&hcx, true)); .with_stable_hashing_context(|mut hcx| tcx.reachable_set(()).to_sorted(&mut hcx, true));
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
// This is based on: // This is based on:
// https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L62-L63 // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L62-L63