Skip to content

Commit fdb5fe2

Browse files
committed
Change LoweringContext.children to Vec
1 parent d1eab51 commit fdb5fe2

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

compiler/rustc_ast_lowering/src/item.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::{FnDeclKind, LoweringContext, ParamMode};
66
use rustc_ast::ptr::P;
77
use rustc_ast::visit::AssocCtxt;
88
use rustc_ast::*;
9-
use rustc_data_structures::fx::FxHashMap;
109
use rustc_data_structures::sorted_map::SortedMap;
1110
use rustc_hir as hir;
1211
use rustc_hir::def::{DefKind, Res};
@@ -67,7 +66,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6766
// HirId handling.
6867
bodies: Vec::new(),
6968
attrs: SortedMap::default(),
70-
children: FxHashMap::default(),
69+
children: Vec::default(),
7170
current_hir_id_owner: hir::CRATE_OWNER_ID,
7271
item_local_id_counter: hir::ItemLocalId::new(0),
7372
node_id_to_local_id: Default::default(),
@@ -95,7 +94,13 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
9594
for (def_id, info) in lctx.children {
9695
self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
9796
debug_assert!(matches!(self.owners[def_id], hir::MaybeOwner::Phantom));
98-
self.owners[def_id] = info;
97+
match (self.owners[def_id], info) {
98+
(hir::MaybeOwner::Phantom, _)
99+
| (hir::MaybeOwner::NonOwner(_), hir::MaybeOwner::Owner(_)) => {
100+
self.owners[def_id] = info;
101+
}
102+
_ => unreachable!(),
103+
}
99104
}
100105
}
101106

@@ -534,12 +539,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
534539
for new_node_id in [id1, id2] {
535540
let new_id = self.local_def_id(new_node_id);
536541
let Some(res) = resolutions.next() else {
542+
debug_assert!(self.children.iter().find(|(id, _)| id == &new_id).is_none());
537543
// Associate an HirId to both ids even if there is no resolution.
538-
let _old = self.children.insert(
544+
self.children.push((
539545
new_id,
540-
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id)),
546+
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id))),
541547
);
542-
debug_assert!(_old.is_none());
543548
continue;
544549
};
545550
let ident = *ident;

compiler/rustc_ast_lowering/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct LoweringContext<'a, 'hir> {
106106
/// Attributes inside the owner being lowered.
107107
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
108108
/// Collect items that were created by lowering the current owner.
109-
children: FxHashMap<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
109+
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
110110

111111
generator_kind: Option<hir::GeneratorKind>,
112112

@@ -610,8 +610,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
610610
self.impl_trait_defs = current_impl_trait_defs;
611611
self.impl_trait_bounds = current_impl_trait_bounds;
612612

613-
let _old = self.children.insert(def_id, hir::MaybeOwner::Owner(info));
614-
debug_assert!(_old.is_none())
613+
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
614+
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
615615
}
616616

617617
/// Installs the remapping `remap` in scope while `f` is being executed.
@@ -718,8 +718,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
718718

719719
assert_ne!(local_id, hir::ItemLocalId::new(0));
720720
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
721-
// Do not override a `MaybeOwner::Owner` that may already here.
722-
self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id));
721+
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
723722
self.local_id_to_def_id.insert(local_id, def_id);
724723
}
725724

0 commit comments

Comments
 (0)