diff options
| author | Michael Goulet <michael@errs.io> | 2023-11-19 19:14:32 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 19:14:32 -0800 |
| commit | b39791aec23c0319aaf043e98ea3bd0435808f8a (patch) | |
| tree | 498579f652f761ac4cb4b75edf41d19be7a5b0ee | |
| parent | 4f3da903a43f22ea33d2ca4435a24b42fc1f842a (diff) | |
| parent | 13959bf376445baa6336bc9cf9c46c46c83e8820 (diff) | |
| download | rust-b39791aec23c0319aaf043e98ea3bd0435808f8a.tar.gz rust-b39791aec23c0319aaf043e98ea3bd0435808f8a.zip | |
Rollup merge of #117828 - Nilstrieb:astconv-hashmaps, r=petrochenkov
Avoid iterating over hashmaps in astconv
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/errors.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/object_safety.rs | 6 | ||||
| -rw-r--r-- | tests/ui/associated-types/missing-associated-types.stderr | 4 |
3 files changed, 8 insertions, 12 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 7ced37e5694..8f4b83966df 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -4,7 +4,7 @@ use crate::errors::{ ParenthesizedFnTraitExpansion, }; use crate::traits::error_reporting::report_object_safety_error; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -16,8 +16,6 @@ use rustc_span::symbol::{sym, Ident}; use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_trait_selection::traits::object_safety_violations_for_assoc_item; -use std::collections::BTreeSet; - impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { /// On missing type parameters, emit an E0393 error and provide a structured suggestion using /// the type parameter's name as a placeholder. @@ -504,7 +502,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { /// emit a generic note suggesting using a `where` clause to constraint instead. pub(crate) fn complain_about_missing_associated_types( &self, - associated_types: FxHashMap<Span, BTreeSet<DefId>>, + associated_types: FxIndexMap<Span, FxIndexSet<DefId>>, potential_assoc_types: Vec<Span>, trait_bounds: &[hir::PolyTraitRef<'_>], ) { @@ -514,13 +512,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.tcx(); // FIXME: Marked `mut` so that we can replace the spans further below with a more // appropriate one, but this should be handled earlier in the span assignment. - let mut associated_types: FxHashMap<Span, Vec<_>> = associated_types + let mut associated_types: FxIndexMap<Span, Vec<_>> = associated_types .into_iter() .map(|(span, def_ids)| { (span, def_ids.into_iter().map(|did| tcx.associated_item(did)).collect()) }) .collect(); - let mut names: FxHashMap<String, Vec<Symbol>> = Default::default(); + let mut names: FxIndexMap<String, Vec<Symbol>> = Default::default(); let mut names_len = 0; // Account for things like `dyn Foo + 'a`, like in tests `issue-22434.rs` and diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index 00ff3f836ad..78c5809f8b4 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -1,7 +1,7 @@ use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBounds}; use crate::bounds::Bounds; use crate::errors::TraitObjectDeclaredWithNoTraits; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -14,7 +14,6 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::{self, astconv_object_safety_violations}; use smallvec::{smallvec, SmallVec}; -use std::collections::BTreeSet; use super::AstConv; @@ -148,8 +147,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } - // Use a `BTreeSet` to keep output in a more consistent order. - let mut associated_types: FxHashMap<Span, BTreeSet<DefId>> = FxHashMap::default(); + let mut associated_types: FxIndexMap<Span, FxIndexSet<DefId>> = FxIndexMap::default(); let regular_traits_refs_spans = trait_bounds .into_iter() diff --git a/tests/ui/associated-types/missing-associated-types.stderr b/tests/ui/associated-types/missing-associated-types.stderr index e9669afe8c7..0636667ea1f 100644 --- a/tests/ui/associated-types/missing-associated-types.stderr +++ b/tests/ui/associated-types/missing-associated-types.stderr @@ -49,7 +49,7 @@ LL | type B; LL | type Bar<Rhs> = dyn Add<Rhs> + Sub<Rhs> + X<Rhs> + Z<Rhs>; | ^^^^^^^^ ^^^^^^^^ ^^^^^^ ^^^^^^ associated types `A`, `B`, `Output` must be specified | | | | - | | | associated types `Output` (from trait `Mul`), `Output` (from trait `Div`) must be specified + | | | associated types `Output` (from trait `Div`), `Output` (from trait `Mul`) must be specified | | associated type `Output` must be specified | associated type `Output` must be specified | @@ -119,7 +119,7 @@ error[E0191]: the value of the associated types `Output` in `Div`, `Output` in ` --> $DIR/missing-associated-types.rs:24:21 | LL | type Bal<Rhs> = dyn X<Rhs>; - | ^^^^^^ associated types `Output` (from trait `Mul`), `Output` (from trait `Div`) must be specified + | ^^^^^^ associated types `Output` (from trait `Div`), `Output` (from trait `Mul`) must be specified | = help: consider introducing a new type parameter, adding `where` constraints using the fully-qualified path to the associated types |
