Skip to content

Commit 73a1587

Browse files
committed
Avoid iterating over hashmaps in astconv
1 parent ed086d8 commit 73a1587

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

compiler/rustc_hir_analysis/src/astconv/errors.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::errors::{
44
ParenthesizedFnTraitExpansion,
55
};
66
use crate::traits::error_reporting::report_object_safety_error;
7-
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
88
use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
99
use rustc_hir as hir;
1010
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -16,8 +16,6 @@ use rustc_span::symbol::{sym, Ident};
1616
use rustc_span::{Span, Symbol, DUMMY_SP};
1717
use rustc_trait_selection::traits::object_safety_violations_for_assoc_item;
1818

19-
use std::collections::BTreeSet;
20-
2119
impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2220
/// On missing type parameters, emit an E0393 error and provide a structured suggestion using
2321
/// the type parameter's name as a placeholder.
@@ -506,7 +504,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
506504
/// emit a generic note suggesting using a `where` clause to constraint instead.
507505
pub(crate) fn complain_about_missing_associated_types(
508506
&self,
509-
associated_types: FxHashMap<Span, BTreeSet<DefId>>,
507+
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
510508
potential_assoc_types: Vec<Span>,
511509
trait_bounds: &[hir::PolyTraitRef<'_>],
512510
) {
@@ -516,13 +514,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
516514
let tcx = self.tcx();
517515
// FIXME: Marked `mut` so that we can replace the spans further below with a more
518516
// appropriate one, but this should be handled earlier in the span assignment.
519-
let mut associated_types: FxHashMap<Span, Vec<_>> = associated_types
517+
let mut associated_types: FxIndexMap<Span, Vec<_>> = associated_types
520518
.into_iter()
521519
.map(|(span, def_ids)| {
522520
(span, def_ids.into_iter().map(|did| tcx.associated_item(did)).collect())
523521
})
524522
.collect();
525-
let mut names: FxHashMap<String, Vec<Symbol>> = Default::default();
523+
let mut names: FxIndexMap<String, Vec<Symbol>> = Default::default();
526524
let mut names_len = 0;
527525

528526
// Account for things like `dyn Foo + 'a`, like in tests `issue-22434.rs` and

compiler/rustc_hir_analysis/src/astconv/object_safety.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBounds};
22
use crate::bounds::Bounds;
33
use crate::errors::TraitObjectDeclaredWithNoTraits;
4-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
55
use rustc_errors::struct_span_err;
66
use rustc_hir as hir;
77
use rustc_hir::def::{DefKind, Res};
@@ -14,7 +14,6 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
1414
use rustc_trait_selection::traits::{self, astconv_object_safety_violations};
1515

1616
use smallvec::{smallvec, SmallVec};
17-
use std::collections::BTreeSet;
1817

1918
use super::AstConv;
2019

@@ -148,8 +147,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
148147
}
149148
}
150149

151-
// Use a `BTreeSet` to keep output in a more consistent order.
152-
let mut associated_types: FxHashMap<Span, BTreeSet<DefId>> = FxHashMap::default();
150+
let mut associated_types: FxIndexMap<Span, FxIndexSet<DefId>> = FxIndexMap::default();
153151

154152
let regular_traits_refs_spans = trait_bounds
155153
.into_iter()

0 commit comments

Comments
 (0)