-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HirIdify hir::ItemId #59092
HirIdify hir::ItemId #59092
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ pub struct LoweringContext<'a> { | |
resolver: &'a mut dyn Resolver, | ||
|
||
/// The items being lowered are collected here. | ||
items: BTreeMap<NodeId, hir::Item>, | ||
items: BTreeMap<hir::HirId, hir::Item>, | ||
|
||
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem>, | ||
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>, | ||
|
@@ -323,7 +323,7 @@ enum AnonymousLifetimeMode { | |
PassThrough, | ||
} | ||
|
||
struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut SmallVec<[hir::ItemId; 1]> } | ||
struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut SmallVec<[NodeId; 1]> } | ||
|
||
impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> { | ||
fn visit_ty(&mut self, ty: &'a Ty) { | ||
|
@@ -332,7 +332,7 @@ impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> { | |
| TyKind::BareFn(_) | ||
=> return, | ||
|
||
TyKind::ImplTrait(id, _) => self.ids.push(hir::ItemId { id }), | ||
TyKind::ImplTrait(id, _) => self.ids.push(id), | ||
_ => {}, | ||
} | ||
visit::walk_ty(self, ty); | ||
|
@@ -436,17 +436,16 @@ impl<'a> LoweringContext<'a> { | |
} | ||
|
||
fn visit_item(&mut self, item: &'lcx Item) { | ||
let mut item_lowered = true; | ||
let mut item_hir_id = None; | ||
self.lctx.with_hir_id_owner(item.id, |lctx| { | ||
if let Some(hir_item) = lctx.lower_item(item) { | ||
lctx.insert_item(item.id, hir_item); | ||
} else { | ||
item_lowered = false; | ||
item_hir_id = Some(hir_item.hir_id); | ||
lctx.insert_item(hir_item); | ||
} | ||
}); | ||
|
||
if item_lowered { | ||
let item_generics = match self.lctx.items.get(&item.id).unwrap().node { | ||
if let Some(hir_id) = item_hir_id { | ||
let item_generics = match self.lctx.items.get(&hir_id).unwrap().node { | ||
hir::ItemKind::Impl(_, _, _, ref generics, ..) | ||
| hir::ItemKind::Trait(_, _, ref generics, ..) => { | ||
generics.params.clone() | ||
|
@@ -519,7 +518,8 @@ impl<'a> LoweringContext<'a> { | |
} | ||
} | ||
|
||
fn insert_item(&mut self, id: NodeId, item: hir::Item) { | ||
fn insert_item(&mut self, item: hir::Item) { | ||
let id = item.hir_id; | ||
self.items.insert(id, item); | ||
self.modules.get_mut(&self.current_module).unwrap().items.insert(id); | ||
} | ||
|
@@ -1425,10 +1425,10 @@ impl<'a> LoweringContext<'a> { | |
// Insert the item into the global list. This usually happens | ||
// automatically for all AST items. But this existential type item | ||
// does not actually exist in the AST. | ||
lctx.insert_item(exist_ty_id.node_id, exist_ty_item); | ||
lctx.insert_item(exist_ty_item); | ||
|
||
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`. | ||
hir::TyKind::Def(hir::ItemId { id: exist_ty_id.node_id }, lifetimes) | ||
hir::TyKind::Def(hir::ItemId { id: exist_ty_id.hir_id }, lifetimes) | ||
}) | ||
} | ||
|
||
|
@@ -2003,9 +2003,9 @@ impl<'a> LoweringContext<'a> { | |
) | ||
} | ||
|
||
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) { | ||
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[NodeId; 1]>) { | ||
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id); | ||
let mut ids = SmallVec::<[hir::ItemId; 1]>::new(); | ||
let mut ids = SmallVec::<[NodeId; 1]>::new(); | ||
if self.sess.features_untracked().impl_trait_in_bindings { | ||
if let Some(ref ty) = l.ty { | ||
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids }; | ||
|
@@ -3122,7 +3122,6 @@ impl<'a> LoweringContext<'a> { | |
let vis = respan(vis.span, vis_kind); | ||
|
||
this.insert_item( | ||
new_id.node_id, | ||
hir::Item { | ||
hir_id: new_id.hir_id, | ||
ident, | ||
|
@@ -3227,7 +3226,6 @@ impl<'a> LoweringContext<'a> { | |
let vis = respan(vis.span, vis_kind); | ||
|
||
this.insert_item( | ||
new_id, | ||
hir::Item { | ||
hir_id: new_hir_id, | ||
ident, | ||
|
@@ -3451,43 +3449,47 @@ impl<'a> LoweringContext<'a> { | |
} | ||
|
||
fn lower_item_id(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> { | ||
match i.node { | ||
let node_ids = match i.node { | ||
ItemKind::Use(ref use_tree) => { | ||
let mut vec = smallvec![hir::ItemId { id: i.id }]; | ||
let mut vec = smallvec![i.id]; | ||
self.lower_item_id_use_tree(use_tree, i.id, &mut vec); | ||
vec | ||
} | ||
ItemKind::MacroDef(..) => SmallVec::new(), | ||
ItemKind::Fn(..) | | ||
ItemKind::Impl(.., None, _, _) => smallvec![hir::ItemId { id: i.id }], | ||
ItemKind::Impl(.., None, _, _) => smallvec![i.id], | ||
ItemKind::Static(ref ty, ..) => { | ||
let mut ids = smallvec![hir::ItemId { id: i.id }]; | ||
let mut ids = smallvec![i.id]; | ||
if self.sess.features_untracked().impl_trait_in_bindings { | ||
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids }; | ||
visitor.visit_ty(ty); | ||
} | ||
ids | ||
}, | ||
ItemKind::Const(ref ty, ..) => { | ||
let mut ids = smallvec![hir::ItemId { id: i.id }]; | ||
let mut ids = smallvec![i.id]; | ||
if self.sess.features_untracked().impl_trait_in_bindings { | ||
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids }; | ||
visitor.visit_ty(ty); | ||
} | ||
ids | ||
}, | ||
_ => smallvec![hir::ItemId { id: i.id }], | ||
} | ||
_ => smallvec![i.id], | ||
}; | ||
|
||
node_ids.into_iter() | ||
.map(|node_id| hir::ItemId { id: self.lower_node_id(node_id).hir_id }) | ||
.collect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced this with:
That panics and shows the the following item wasn't assigned a
I guess this means that either too many @oli-obk Do you have any ideas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These node ids haven't been lowered yet at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that only AST items had their ids lowered in |
||
} | ||
|
||
fn lower_item_id_use_tree(&mut self, | ||
tree: &UseTree, | ||
base_id: NodeId, | ||
vec: &mut SmallVec<[hir::ItemId; 1]>) | ||
vec: &mut SmallVec<[NodeId; 1]>) | ||
{ | ||
match tree.kind { | ||
UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec { | ||
vec.push(hir::ItemId { id }); | ||
vec.push(id); | ||
self.lower_item_id_use_tree(nested, id, vec); | ||
}, | ||
UseTreeKind::Glob => {} | ||
|
@@ -3496,7 +3498,7 @@ impl<'a> LoweringContext<'a> { | |
.skip(1) | ||
.zip([id1, id2].iter()) | ||
{ | ||
vec.push(hir::ItemId { id }); | ||
vec.push(id); | ||
} | ||
}, | ||
} | ||
|
@@ -4611,6 +4613,7 @@ impl<'a> LoweringContext<'a> { | |
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids | ||
.into_iter() | ||
.map(|item_id| { | ||
let item_id = hir::ItemId { id: self.lower_node_id(item_id).hir_id }; | ||
let LoweredNodeId { node_id: _, hir_id } = self.next_id(); | ||
|
||
hir::Stmt { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could try asserting that the local id of the item is 0 here?
You could also try printing out information about the item which isn't 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got one: