Skip to content

Commit 52e003a

Browse files
committed
Auto merge of #99334 - NiklasJonsson:84447/error-privacy, r=oli-obk
rustc_error, rustc_private: Switch to stable hash containers Relates #84447
2 parents 7f115e3 + 8d3c30c commit 52e003a

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

compiler/rustc_ast/src/node_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rustc_index::newtype_index! {
1313
}
1414
}
1515

16-
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
16+
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
1717

1818
/// The [`NodeId`] used to represent the root of the crate.
1919
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);

compiler/rustc_data_structures/src/fx.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ use std::hash::BuildHasherDefault;
22

33
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
44

5+
pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
6+
57
pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
68
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
9+
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
710

811
#[macro_export]
912
macro_rules! define_id_collections {
10-
($map_name:ident, $set_name:ident, $key:ty) => {
13+
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
1114
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
1215
pub type $set_name = $crate::fx::FxHashSet<$key>;
16+
pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
17+
};
18+
}
19+
20+
#[macro_export]
21+
macro_rules! define_stable_id_collections {
22+
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
23+
pub type $map_name<T> = $crate::fx::FxIndexMap<$key, T>;
24+
pub type $set_name = $crate::fx::FxIndexSet<$key>;
25+
pub type $entry_name<'a, T> = $crate::fx::IndexEntry<'a, $key, T>;
1326
};
1427
}

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222

2323
use rustc_lint_defs::pluralize;
2424

25-
use rustc_data_structures::fx::FxHashMap;
25+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
2626
use rustc_data_structures::sync::Lrc;
2727
use rustc_error_messages::FluentArgs;
2828
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -1487,7 +1487,7 @@ impl EmitterWriter {
14871487
);
14881488

14891489
// Contains the vertical lines' positions for active multiline annotations
1490-
let mut multilines = FxHashMap::default();
1490+
let mut multilines = FxIndexMap::default();
14911491

14921492
// Get the left-side margin to remove it
14931493
let mut whitespace_margin = usize::MAX;

compiler/rustc_errors/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![feature(result_option_inspect)]
1313
#![feature(rustc_attrs)]
1414
#![allow(incomplete_features)]
15-
#![allow(rustc::potential_query_instability)]
1615

1716
#[macro_use]
1817
extern crate rustc_macros;
@@ -27,7 +26,7 @@ use Level::*;
2726

2827
use emitter::{is_case_difference, Emitter, EmitterWriter};
2928
use registry::Registry;
30-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
29+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3130
use rustc_data_structures::stable_hasher::StableHasher;
3231
use rustc_data_structures::sync::{self, Lock, Lrc};
3332
use rustc_data_structures::AtomicRef;
@@ -413,7 +412,7 @@ struct HandlerInner {
413412
taught_diagnostics: FxHashSet<DiagnosticId>,
414413

415414
/// Used to suggest rustc --explain <error code>
416-
emitted_diagnostic_codes: FxHashSet<DiagnosticId>,
415+
emitted_diagnostic_codes: FxIndexSet<DiagnosticId>,
417416

418417
/// This set contains a hash of every diagnostic that has been emitted by
419418
/// this handler. These hashes is used to avoid emitting the same error

compiler/rustc_hir/src/hir_id.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ impl PartialOrd for HirId {
6767
}
6868
}
6969

70-
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
71-
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
70+
rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId);
71+
rustc_data_structures::define_id_collections!(
72+
ItemLocalMap,
73+
ItemLocalSet,
74+
ItemLocalMapEntry,
75+
ItemLocalId
76+
);
7277

7378
rustc_index::newtype_index! {
7479
/// An `ItemLocalId` uniquely identifies something within a given "item-like";

compiler/rustc_privacy/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(rustc_private)]
66
#![feature(try_blocks)]
77
#![recursion_limit = "256"]
8-
#![allow(rustc::potential_query_instability)]
98
#![deny(rustc::untranslatable_diagnostic)]
109
#![deny(rustc::diagnostic_outside_of_impl)]
1110

compiler/rustc_span/src/def_id.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl fmt::Debug for DefId {
337337
}
338338
}
339339

340-
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
340+
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefIdMapEntry, DefId);
341341

342342
/// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since
343343
/// we encode this information in the type, we can ensure at compile time that
@@ -399,7 +399,12 @@ impl<D: Decoder> Decodable<D> for LocalDefId {
399399
}
400400
}
401401

402-
rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId);
402+
rustc_data_structures::define_id_collections!(
403+
LocalDefIdMap,
404+
LocalDefIdSet,
405+
LocalDefIdMapEntry,
406+
LocalDefId
407+
);
403408

404409
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
405410
#[inline]

src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use rustc_arena::DroplessArena;
88
use rustc_ast::ast::LitKind;
99
use rustc_errors::Applicability;
1010
use rustc_hir::def_id::DefId;
11-
use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdSet, Pat, PatKind, RangeEnd};
11+
use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd};
1212
use rustc_lint::LateContext;
1313
use rustc_middle::ty;
1414
use rustc_span::Symbol;
15-
use std::collections::hash_map::Entry;
1615

1716
use super::MATCH_SAME_ARMS;
1817

@@ -71,9 +70,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
7170
if let Some(a_id) = path_to_local(a);
7271
if let Some(b_id) = path_to_local(b);
7372
let entry = match local_map.entry(a_id) {
74-
Entry::Vacant(entry) => entry,
73+
HirIdMapEntry::Vacant(entry) => entry,
7574
// check if using the same bindings as before
76-
Entry::Occupied(entry) => return *entry.get() == b_id,
75+
HirIdMapEntry::Occupied(entry) => return *entry.get() == b_id,
7776
};
7877
// the names technically don't have to match; this makes the lint more conservative
7978
if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id);

0 commit comments

Comments
 (0)