Change LoweringContext.children to Vec
This commit is contained in:
parent
d1eab51f47
commit
fdb5fe2ed8
@ -6,7 +6,6 @@
|
|||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::AssocCtxt;
|
use rustc_ast::visit::AssocCtxt;
|
||||||
use rustc_ast::*;
|
use rustc_ast::*;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
|
||||||
use rustc_data_structures::sorted_map::SortedMap;
|
use rustc_data_structures::sorted_map::SortedMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
@ -67,7 +66,7 @@ fn with_lctx(
|
|||||||
// HirId handling.
|
// HirId handling.
|
||||||
bodies: Vec::new(),
|
bodies: Vec::new(),
|
||||||
attrs: SortedMap::default(),
|
attrs: SortedMap::default(),
|
||||||
children: FxHashMap::default(),
|
children: Vec::default(),
|
||||||
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
||||||
item_local_id_counter: hir::ItemLocalId::new(0),
|
item_local_id_counter: hir::ItemLocalId::new(0),
|
||||||
node_id_to_local_id: Default::default(),
|
node_id_to_local_id: Default::default(),
|
||||||
@ -95,7 +94,13 @@ fn with_lctx(
|
|||||||
for (def_id, info) in lctx.children {
|
for (def_id, info) in lctx.children {
|
||||||
self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
|
self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
|
||||||
debug_assert!(matches!(self.owners[def_id], hir::MaybeOwner::Phantom));
|
debug_assert!(matches!(self.owners[def_id], hir::MaybeOwner::Phantom));
|
||||||
self.owners[def_id] = info;
|
match (self.owners[def_id], info) {
|
||||||
|
(hir::MaybeOwner::Phantom, _)
|
||||||
|
| (hir::MaybeOwner::NonOwner(_), hir::MaybeOwner::Owner(_)) => {
|
||||||
|
self.owners[def_id] = info;
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,12 +539,12 @@ fn lower_use_tree(
|
|||||||
for new_node_id in [id1, id2] {
|
for new_node_id in [id1, id2] {
|
||||||
let new_id = self.local_def_id(new_node_id);
|
let new_id = self.local_def_id(new_node_id);
|
||||||
let Some(res) = resolutions.next() else {
|
let Some(res) = resolutions.next() else {
|
||||||
|
debug_assert!(self.children.iter().find(|(id, _)| id == &new_id).is_none());
|
||||||
// Associate an HirId to both ids even if there is no resolution.
|
// Associate an HirId to both ids even if there is no resolution.
|
||||||
let _old = self.children.insert(
|
self.children.push((
|
||||||
new_id,
|
new_id,
|
||||||
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id)),
|
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id))),
|
||||||
);
|
);
|
||||||
debug_assert!(_old.is_none());
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let ident = *ident;
|
let ident = *ident;
|
||||||
|
@ -106,7 +106,7 @@ struct LoweringContext<'a, 'hir> {
|
|||||||
/// Attributes inside the owner being lowered.
|
/// Attributes inside the owner being lowered.
|
||||||
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
|
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
|
||||||
/// Collect items that were created by lowering the current owner.
|
/// Collect items that were created by lowering the current owner.
|
||||||
children: FxHashMap<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
|
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
|
||||||
|
|
||||||
generator_kind: Option<hir::GeneratorKind>,
|
generator_kind: Option<hir::GeneratorKind>,
|
||||||
|
|
||||||
@ -610,8 +610,8 @@ fn with_hir_id_owner(
|
|||||||
self.impl_trait_defs = current_impl_trait_defs;
|
self.impl_trait_defs = current_impl_trait_defs;
|
||||||
self.impl_trait_bounds = current_impl_trait_bounds;
|
self.impl_trait_bounds = current_impl_trait_bounds;
|
||||||
|
|
||||||
let _old = self.children.insert(def_id, hir::MaybeOwner::Owner(info));
|
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
|
||||||
debug_assert!(_old.is_none())
|
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Installs the remapping `remap` in scope while `f` is being executed.
|
/// Installs the remapping `remap` in scope while `f` is being executed.
|
||||||
@ -718,8 +718,7 @@ fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
|
|||||||
|
|
||||||
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
||||||
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
|
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
|
||||||
// Do not override a `MaybeOwner::Owner` that may already here.
|
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
||||||
self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id));
|
|
||||||
self.local_id_to_def_id.insert(local_id, def_id);
|
self.local_id_to_def_id.insert(local_id, def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user