Rollup merge of #138837 - petrochenkov:resinstab2, r=jieyouxu

resolve: Avoid remaining unstable iteration

Continuation of #138580.
This should be the performance sensitive part.
This commit is contained in:
Takayuki Maeda
2025-03-25 15:36:35 +09:00
committed by GitHub
2 changed files with 6 additions and 12 deletions
+6 -7
View File
@@ -272,7 +272,7 @@ fn is_label_barrier(self) -> bool {
/// resolving, the name is looked up from inside out.
#[derive(Debug)]
pub(crate) struct Rib<'ra, R = Res> {
pub bindings: FxHashMap<Ident, R>,
pub bindings: FxIndexMap<Ident, R>,
pub patterns_with_skipped_bindings: UnordMap<DefId, Vec<(Span, Result<(), ErrorGuaranteed>)>>,
pub kind: RibKind<'ra>,
}
@@ -1639,8 +1639,8 @@ fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper:
// Allow all following defaults to refer to this type parameter.
let i = &Ident::with_dummy_span(param.ident.name);
forward_ty_ban_rib.bindings.remove(i);
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
forward_ty_ban_rib.bindings.swap_remove(i);
forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
}
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
// Const parameters can't have param bounds.
@@ -1675,8 +1675,8 @@ fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper:
// Allow all following defaults to refer to this const parameter.
let i = &Ident::with_dummy_span(param.ident.name);
forward_const_ban_rib.bindings.remove(i);
forward_const_ban_rib_const_param_ty.bindings.remove(i);
forward_const_ban_rib.bindings.swap_remove(i);
forward_const_ban_rib_const_param_ty.bindings.swap_remove(i);
}
}
}
@@ -2885,7 +2885,6 @@ fn with_generic_param_rib<'c, F>(
break;
}
#[allow(rustc::potential_query_instability)] // FIXME
seen_bindings
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
}
@@ -4000,7 +3999,7 @@ fn fresh_binding(
}
}
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxHashMap<Ident, Res> {
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
&mut self.ribs[ns].last_mut().unwrap().bindings
}
@@ -830,7 +830,6 @@ fn try_lookup_name_relaxed(
if let Some(rib) = &self.last_block_rib
&& let RibKind::Normal = rib.kind
{
#[allow(rustc::potential_query_instability)] // FIXME
for (ident, &res) in &rib.bindings {
if let Res::Local(_) = res
&& path.len() == 1
@@ -1019,7 +1018,6 @@ fn err_code_special_cases(
if let Some(err_code) = err.code {
if err_code == E0425 {
for label_rib in &self.label_ribs {
#[allow(rustc::potential_query_instability)] // FIXME
for (label_ident, node_id) in &label_rib.bindings {
let ident = path.last().unwrap().ident;
if format!("'{ident}") == label_ident.to_string() {
@@ -2265,7 +2263,6 @@ fn lookup_typo_candidate(
};
// Locals and type parameters
#[allow(rustc::potential_query_instability)] // FIXME
for (ident, &res) in &rib.bindings {
if filter_fn(res) && ident.span.ctxt() == rib_ctxt {
names.push(TypoSuggestion::typo_from_ident(*ident, res));
@@ -2793,7 +2790,6 @@ pub(crate) fn suggestion_for_label_in_rib(
let within_scope = self.is_label_valid_from_rib(rib_index);
let rib = &self.label_ribs[rib_index];
#[allow(rustc::potential_query_instability)] // FIXME
let names = rib
.bindings
.iter()
@@ -2805,7 +2801,6 @@ pub(crate) fn suggestion_for_label_in_rib(
// Upon finding a similar name, get the ident that it was from - the span
// contained within helps make a useful diagnostic. In addition, determine
// whether this candidate is within scope.
#[allow(rustc::potential_query_instability)] // FIXME
let (ident, _) = rib.bindings.iter().find(|(ident, _)| ident.name == symbol).unwrap();
(*ident, within_scope)
})