Skip to content

Commit 84767e0

Browse files
committed
replace FxHashMap with FxIndexMap in rustc_hir_analysis and rustc_errors
1 parent e6c1f16 commit 84767e0

File tree

11 files changed

+33
-36
lines changed

11 files changed

+33
-36
lines changed

compiler/rustc_errors/src/diagnostic.rs

-3
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,6 @@ impl Diagnostic {
888888
self
889889
}
890890

891-
// Exact iteration order of diagnostic arguments shouldn't make a difference to output because
892-
// they're only used in interpolation.
893-
#[allow(rustc::potential_query_instability)]
894891
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_>> {
895892
self.args.iter()
896893
}

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::fx::FxHashMap;
1+
use rustc_data_structures::fx::FxIndexMap;
22
use rustc_errors::{codes::*, struct_span_code_err};
33
use rustc_hir as hir;
44
use rustc_hir::def::{DefKind, Res};
@@ -241,7 +241,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
241241
binding: &ConvertedBinding<'_, 'tcx>,
242242
bounds: &mut Bounds<'tcx>,
243243
speculative: bool,
244-
dup_bindings: &mut FxHashMap<DefId, Span>,
244+
dup_bindings: &mut FxIndexMap<DefId, Span>,
245245
path_span: Span,
246246
only_self_bounds: OnlySelfBounds,
247247
) -> Result<(), ErrorGuaranteed> {

compiler/rustc_hir_analysis/src/astconv/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::errors::{
55
};
66
use crate::fluent_generated as fluent;
77
use crate::traits::error_reporting::report_object_safety_error;
8-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
8+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
99
use rustc_data_structures::sorted_map::SortedMap;
1010
use rustc_data_structures::unord::UnordMap;
1111
use rustc_errors::{
@@ -806,7 +806,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
806806
if suggestions.len() != 1 || already_has_generics_args_suggestion {
807807
// We don't need this label if there's an inline suggestion, show otherwise.
808808
for (span, assoc_items) in &associated_types {
809-
let mut names: FxHashMap<_, usize> = FxHashMap::default();
809+
let mut names: FxIndexMap<_, usize> = FxIndexMap::default();
810810
for item in assoc_items {
811811
types_count += 1;
812812
*names.entry(item.name).or_insert(0) += 1;

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::errors::AmbiguousLifetimeBound;
1616
use crate::middle::resolve_bound_vars as rbv;
1717
use crate::require_c_abi_if_c_variadic;
1818
use rustc_ast::TraitObjectSyntax;
19-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
19+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2020
use rustc_errors::{
2121
codes::*, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
2222
FatalError, MultiSpan,
@@ -750,7 +750,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
750750
debug!(?poly_trait_ref, ?assoc_bindings);
751751
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
752752

753-
let mut dup_bindings = FxHashMap::default();
753+
let mut dup_bindings = FxIndexMap::default();
754754
for binding in &assoc_bindings {
755755
// Don't register additional associated type bounds for negative bounds,
756756
// since we should have emitten an error for them earlier, and they will

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
13101310
// `Sized` bounds. If they came last for example, this would break `Trait + /*elab*/Sized`
13111311
// since it would overwrite the span of the user-written bound. This could be fixed by
13121312
// folding the spans with `Span::to` which requires a bit of effort I think.
1313-
.collect::<FxHashMap<_, _>>()
1313+
.collect::<FxIndexMap<_, _>>()
13141314
});
13151315

13161316
let mut params_used = BitSet::new_empty(generics.params.len());

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::potentially_plural_count;
22
use crate::errors::{LifetimesOrBoundsMismatchOnTrait, MethodShouldReturnFuture};
33
use hir::def_id::{DefId, DefIdMap, LocalDefId};
4-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
4+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
55
use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, ErrorGuaranteed};
66
use rustc_hir as hir;
77
use rustc_hir::def::{DefKind, Res};
@@ -392,7 +392,7 @@ fn compare_method_predicate_entailment<'tcx>(
392392

393393
struct RemapLateBound<'a, 'tcx> {
394394
tcx: TyCtxt<'tcx>,
395-
mapping: &'a FxHashMap<ty::BoundRegionKind, ty::BoundRegionKind>,
395+
mapping: &'a FxIndexMap<ty::BoundRegionKind, ty::BoundRegionKind>,
396396
}
397397

398398
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
@@ -553,7 +553,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
553553
// prove below that the hidden types are well formed.
554554
let universe = infcx.create_next_universe();
555555
let mut idx = 0;
556-
let mapping: FxHashMap<_, _> = collector
556+
let mapping: FxIndexMap<_, _> = collector
557557
.types
558558
.iter()
559559
.map(|(_, &(ty, _))| {
@@ -690,7 +690,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
690690
// contains `def_id`'s early-bound regions.
691691
let id_args = GenericArgs::identity_for_item(tcx, def_id);
692692
debug!(?id_args, ?args);
693-
let map: FxHashMap<_, _> = std::iter::zip(args, id_args)
693+
let map: FxIndexMap<_, _> = std::iter::zip(args, id_args)
694694
.skip(tcx.generics_of(trait_m.def_id).count())
695695
.filter_map(|(a, b)| Some((a.as_region()?, b.as_region()?)))
696696
.collect();
@@ -766,7 +766,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
766766

767767
struct ImplTraitInTraitCollector<'a, 'tcx> {
768768
ocx: &'a ObligationCtxt<'a, 'tcx>,
769-
types: FxHashMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>,
769+
types: FxIndexMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>,
770770
span: Span,
771771
param_env: ty::ParamEnv<'tcx>,
772772
body_id: LocalDefId,
@@ -779,7 +779,7 @@ impl<'a, 'tcx> ImplTraitInTraitCollector<'a, 'tcx> {
779779
param_env: ty::ParamEnv<'tcx>,
780780
body_id: LocalDefId,
781781
) -> Self {
782-
ImplTraitInTraitCollector { ocx, types: FxHashMap::default(), span, param_env, body_id }
782+
ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id }
783783
}
784784
}
785785

@@ -838,7 +838,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
838838

839839
struct RemapHiddenTyRegions<'tcx> {
840840
tcx: TyCtxt<'tcx>,
841-
map: FxHashMap<ty::Region<'tcx>, ty::Region<'tcx>>,
841+
map: FxIndexMap<ty::Region<'tcx>, ty::Region<'tcx>>,
842842
num_trait_args: usize,
843843
num_impl_args: usize,
844844
def_id: DefId,

compiler/rustc_hir_analysis/src/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use check::check_abi;
7676

7777
use std::num::NonZeroU32;
7878

79-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
79+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
8080
use rustc_errors::ErrorGuaranteed;
8181
use rustc_errors::{pluralize, struct_span_code_err, Diagnostic, DiagnosticBuilder};
8282
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -307,7 +307,7 @@ fn bounds_from_generic_predicates<'tcx>(
307307
tcx: TyCtxt<'tcx>,
308308
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
309309
) -> (String, String) {
310-
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
310+
let mut types: FxIndexMap<Ty<'tcx>, Vec<DefId>> = FxIndexMap::default();
311311
let mut projections = vec![];
312312
for (predicate, _) in predicates {
313313
debug!("predicate {:?}", predicate);

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1+
use rustc_data_structures::fx::IndexEntry;
2+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
23
use rustc_errors::{codes::*, struct_span_code_err};
34
use rustc_hir as hir;
45
use rustc_hir::def::DefKind;
@@ -9,7 +10,6 @@ use rustc_middle::ty::{self, TyCtxt};
910
use rustc_span::{ErrorGuaranteed, Symbol};
1011
use rustc_trait_selection::traits::{self, SkipLeakCheck};
1112
use smallvec::SmallVec;
12-
use std::collections::hash_map::Entry;
1313

1414
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
1515
let mut inherent_overlap_checker = InherentOverlapChecker { tcx };
@@ -63,15 +63,15 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
6363
fn check_for_duplicate_items_in_impl(&self, impl_: DefId) -> Result<(), ErrorGuaranteed> {
6464
let impl_items = self.tcx.associated_items(impl_);
6565

66-
let mut seen_items = FxHashMap::default();
66+
let mut seen_items = FxIndexMap::default();
6767
let mut res = Ok(());
6868
for impl_item in impl_items.in_definition_order() {
6969
let span = self.tcx.def_span(impl_item.def_id);
7070
let ident = impl_item.ident(self.tcx);
7171

7272
let norm_ident = ident.normalize_to_macros_2_0();
7373
match seen_items.entry(norm_ident) {
74-
Entry::Occupied(entry) => {
74+
IndexEntry::Occupied(entry) => {
7575
let former = entry.get();
7676
res = Err(struct_span_code_err!(
7777
self.tcx.dcx(),
@@ -84,7 +84,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
8484
.with_span_label(*former, format!("other definition for `{ident}`"))
8585
.emit());
8686
}
87-
Entry::Vacant(entry) => {
87+
IndexEntry::Vacant(entry) => {
8888
entry.insert(span);
8989
}
9090
}
@@ -216,7 +216,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
216216
}
217217
let mut connected_regions: IndexVec<RegionId, _> = Default::default();
218218
// Reverse map from the Symbol to the connected region id.
219-
let mut connected_region_ids = FxHashMap::default();
219+
let mut connected_region_ids = FxIndexMap::default();
220220

221221
for (i, &(&_impl_def_id, impl_items)) in impls_items.iter().enumerate() {
222222
if impl_items.len() == 0 {
@@ -228,7 +228,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
228228
.in_definition_order()
229229
.filter_map(|item| {
230230
let entry = connected_region_ids.entry(item.name);
231-
if let Entry::Occupied(e) = &entry {
231+
if let IndexEntry::Occupied(e) = &entry {
232232
Some(*e.get())
233233
} else {
234234
idents_to_add.push(item.name);

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! crate as a kind of pass. This should eventually be factored away.
1616
1717
use rustc_data_structures::captures::Captures;
18-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
18+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1919
use rustc_data_structures::unord::UnordMap;
2020
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
2121
use rustc_hir as hir;
@@ -801,7 +801,7 @@ fn convert_variant(
801801
adt_kind: ty::AdtKind,
802802
parent_did: LocalDefId,
803803
) -> ty::VariantDef {
804-
let mut seen_fields: FxHashMap<Ident, Span> = Default::default();
804+
let mut seen_fields: FxIndexMap<Ident, Span> = Default::default();
805805
let fields = def
806806
.fields()
807807
.iter()

compiler/rustc_hir_analysis/src/outlives/explicit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use rustc_data_structures::fx::FxHashMap;
1+
use rustc_data_structures::fx::FxIndexMap;
22
use rustc_hir::def_id::DefId;
33
use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt};
44

55
use super::utils::*;
66

77
#[derive(Debug)]
88
pub struct ExplicitPredicatesMap<'tcx> {
9-
map: FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
9+
map: FxIndexMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
1010
}
1111

1212
impl<'tcx> ExplicitPredicatesMap<'tcx> {
1313
pub fn new() -> ExplicitPredicatesMap<'tcx> {
14-
ExplicitPredicatesMap { map: FxHashMap::default() }
14+
ExplicitPredicatesMap { map: FxIndexMap::default() }
1515
}
1616

1717
pub(crate) fn explicit_predicates_of(

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::fx::FxHashMap;
1+
use rustc_data_structures::fx::FxIndexMap;
22
use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::DefId;
44
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -15,12 +15,12 @@ use super::utils::*;
1515
/// now be filled with inferred predicates.
1616
pub(super) fn infer_predicates(
1717
tcx: TyCtxt<'_>,
18-
) -> FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'_>>> {
18+
) -> FxIndexMap<DefId, ty::EarlyBinder<RequiredPredicates<'_>>> {
1919
debug!("infer_predicates");
2020

2121
let mut explicit_map = ExplicitPredicatesMap::new();
2222

23-
let mut global_inferred_outlives = FxHashMap::default();
23+
let mut global_inferred_outlives = FxIndexMap::default();
2424

2525
// If new predicates were added then we need to re-calculate
2626
// all crates since there could be new implied predicates.
@@ -101,7 +101,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
101101
tcx: TyCtxt<'tcx>,
102102
ty: Ty<'tcx>,
103103
span: Span,
104-
global_inferred_outlives: &FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
104+
global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
105105
required_predicates: &mut RequiredPredicates<'tcx>,
106106
explicit_map: &mut ExplicitPredicatesMap<'tcx>,
107107
) {
@@ -322,7 +322,7 @@ fn check_inferred_predicates<'tcx>(
322322
tcx: TyCtxt<'tcx>,
323323
def_id: DefId,
324324
args: ty::GenericArgsRef<'tcx>,
325-
global_inferred_outlives: &FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
325+
global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
326326
required_predicates: &mut RequiredPredicates<'tcx>,
327327
) {
328328
// Load the current set of inferred and explicit predicates from `global_inferred_outlives`

0 commit comments

Comments
 (0)