Skip to content

Commit c25e4bf

Browse files
committed
resolve: Avoid some unstable iteration 3
1 parent 0ce1369 commit c25e4bf

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

compiler/rustc_resolve/src/late.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl RibKind<'_> {
272272
/// resolving, the name is looked up from inside out.
273273
#[derive(Debug)]
274274
pub(crate) struct Rib<'ra, R = Res> {
275-
pub bindings: FxHashMap<Ident, R>,
275+
pub bindings: FxIndexMap<Ident, R>,
276276
pub patterns_with_skipped_bindings: UnordMap<DefId, Vec<(Span, Result<(), ErrorGuaranteed>)>>,
277277
pub kind: RibKind<'ra>,
278278
}
@@ -1642,8 +1642,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
16421642

16431643
// Allow all following defaults to refer to this type parameter.
16441644
let i = &Ident::with_dummy_span(param.ident.name);
1645-
forward_ty_ban_rib.bindings.remove(i);
1646-
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
1645+
forward_ty_ban_rib.bindings.swap_remove(i);
1646+
forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
16471647
}
16481648
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
16491649
// Const parameters can't have param bounds.
@@ -1678,8 +1678,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
16781678

16791679
// Allow all following defaults to refer to this const parameter.
16801680
let i = &Ident::with_dummy_span(param.ident.name);
1681-
forward_const_ban_rib.bindings.remove(i);
1682-
forward_const_ban_rib_const_param_ty.bindings.remove(i);
1681+
forward_const_ban_rib.bindings.swap_remove(i);
1682+
forward_const_ban_rib_const_param_ty.bindings.swap_remove(i);
16831683
}
16841684
}
16851685
}
@@ -2888,7 +2888,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28882888
break;
28892889
}
28902890

2891-
#[allow(rustc::potential_query_instability)] // FIXME
28922891
seen_bindings
28932892
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
28942893
}
@@ -4003,7 +4002,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40034002
}
40044003
}
40054004

4006-
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxHashMap<Ident, Res> {
4005+
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
40074006
&mut self.ribs[ns].last_mut().unwrap().bindings
40084007
}
40094008

compiler/rustc_resolve/src/late/diagnostics.rs

-5
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
830830
if let Some(rib) = &self.last_block_rib
831831
&& let RibKind::Normal = rib.kind
832832
{
833-
#[allow(rustc::potential_query_instability)] // FIXME
834833
for (ident, &res) in &rib.bindings {
835834
if let Res::Local(_) = res
836835
&& path.len() == 1
@@ -1019,7 +1018,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
10191018
if let Some(err_code) = err.code {
10201019
if err_code == E0425 {
10211020
for label_rib in &self.label_ribs {
1022-
#[allow(rustc::potential_query_instability)] // FIXME
10231021
for (label_ident, node_id) in &label_rib.bindings {
10241022
let ident = path.last().unwrap().ident;
10251023
if format!("'{ident}") == label_ident.to_string() {
@@ -2265,7 +2263,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
22652263
};
22662264

22672265
// Locals and type parameters
2268-
#[allow(rustc::potential_query_instability)] // FIXME
22692266
for (ident, &res) in &rib.bindings {
22702267
if filter_fn(res) && ident.span.ctxt() == rib_ctxt {
22712268
names.push(TypoSuggestion::typo_from_ident(*ident, res));
@@ -2793,7 +2790,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
27932790
let within_scope = self.is_label_valid_from_rib(rib_index);
27942791

27952792
let rib = &self.label_ribs[rib_index];
2796-
#[allow(rustc::potential_query_instability)] // FIXME
27972793
let names = rib
27982794
.bindings
27992795
.iter()
@@ -2805,7 +2801,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
28052801
// Upon finding a similar name, get the ident that it was from - the span
28062802
// contained within helps make a useful diagnostic. In addition, determine
28072803
// whether this candidate is within scope.
2808-
#[allow(rustc::potential_query_instability)] // FIXME
28092804
let (ident, _) = rib.bindings.iter().find(|(ident, _)| ident.name == symbol).unwrap();
28102805
(*ident, within_scope)
28112806
})

0 commit comments

Comments
 (0)