mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
rustc_error, rustc_private, rustc_ast: Switch to stable hash containers
This commit is contained in:
parent
db9d86b58d
commit
8d3c30c004
@ -13,7 +13,7 @@ rustc_index::newtype_index! {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
|
||||
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
|
||||
|
||||
/// The [`NodeId`] used to represent the root of the crate.
|
||||
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
|
||||
|
@ -2,13 +2,26 @@ use std::hash::BuildHasherDefault;
|
||||
|
||||
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
||||
|
||||
pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
|
||||
|
||||
pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
|
||||
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! define_id_collections {
|
||||
($map_name:ident, $set_name:ident, $key:ty) => {
|
||||
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
|
||||
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
|
||||
pub type $set_name = $crate::fx::FxHashSet<$key>;
|
||||
pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! define_stable_id_collections {
|
||||
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
|
||||
pub type $map_name<T> = $crate::fx::FxIndexMap<$key, T>;
|
||||
pub type $set_name = $crate::fx::FxIndexSet<$key>;
|
||||
pub type $entry_name<'a, T> = $crate::fx::IndexEntry<'a, $key, T>;
|
||||
};
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
|
||||
use rustc_lint_defs::pluralize;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_error_messages::FluentArgs;
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
@ -1487,7 +1487,7 @@ impl EmitterWriter {
|
||||
);
|
||||
|
||||
// Contains the vertical lines' positions for active multiline annotations
|
||||
let mut multilines = FxHashMap::default();
|
||||
let mut multilines = FxIndexMap::default();
|
||||
|
||||
// Get the left-side margin to remove it
|
||||
let mut whitespace_margin = usize::MAX;
|
||||
|
@ -12,7 +12,6 @@
|
||||
#![feature(result_option_inspect)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(incomplete_features)]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
@ -27,7 +26,7 @@ use Level::*;
|
||||
|
||||
use emitter::{is_case_difference, Emitter, EmitterWriter};
|
||||
use registry::Registry;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_data_structures::sync::{self, Lock, Lrc};
|
||||
use rustc_data_structures::AtomicRef;
|
||||
@ -413,7 +412,7 @@ struct HandlerInner {
|
||||
taught_diagnostics: FxHashSet<DiagnosticId>,
|
||||
|
||||
/// Used to suggest rustc --explain <error code>
|
||||
emitted_diagnostic_codes: FxHashSet<DiagnosticId>,
|
||||
emitted_diagnostic_codes: FxIndexSet<DiagnosticId>,
|
||||
|
||||
/// This set contains a hash of every diagnostic that has been emitted by
|
||||
/// this handler. These hashes is used to avoid emitting the same error
|
||||
|
@ -67,8 +67,13 @@ impl PartialOrd for HirId {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
|
||||
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
|
||||
rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId);
|
||||
rustc_data_structures::define_id_collections!(
|
||||
ItemLocalMap,
|
||||
ItemLocalSet,
|
||||
ItemLocalMapEntry,
|
||||
ItemLocalId
|
||||
);
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// An `ItemLocalId` uniquely identifies something within a given "item-like";
|
||||
|
@ -5,7 +5,6 @@
|
||||
#![feature(rustc_private)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
|
@ -337,7 +337,7 @@ impl fmt::Debug for DefId {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
|
||||
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefIdMapEntry, DefId);
|
||||
|
||||
/// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since
|
||||
/// 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 {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId);
|
||||
rustc_data_structures::define_id_collections!(
|
||||
LocalDefIdMap,
|
||||
LocalDefIdSet,
|
||||
LocalDefIdMapEntry,
|
||||
LocalDefId
|
||||
);
|
||||
|
||||
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
|
||||
#[inline]
|
||||
|
@ -8,11 +8,10 @@ use rustc_arena::DroplessArena;
|
||||
use rustc_ast::ast::LitKind;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdSet, Pat, PatKind, RangeEnd};
|
||||
use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::Symbol;
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
use super::MATCH_SAME_ARMS;
|
||||
|
||||
@ -71,9 +70,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
|
||||
if let Some(a_id) = path_to_local(a);
|
||||
if let Some(b_id) = path_to_local(b);
|
||||
let entry = match local_map.entry(a_id) {
|
||||
Entry::Vacant(entry) => entry,
|
||||
HirIdMapEntry::Vacant(entry) => entry,
|
||||
// check if using the same bindings as before
|
||||
Entry::Occupied(entry) => return *entry.get() == b_id,
|
||||
HirIdMapEntry::Occupied(entry) => return *entry.get() == b_id,
|
||||
};
|
||||
// the names technically don't have to match; this makes the lint more conservative
|
||||
if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id);
|
||||
|
Loading…
Reference in New Issue
Block a user