impl<'hir> Entry<'hir> {
fn parent_node(self) -> Option<HirId> {
match self.node {
- Node::Crate(_) | Node::MacroDef(_) => None,
+ Node::Crate(_) => None,
_ => Some(self.parent),
}
}
}
}
-fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
+pub fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
match &node {
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
ItemKind::TraitAlias(..) => DefKind::TraitAlias,
ItemKind::ExternCrate(_) => DefKind::ExternCrate,
ItemKind::Use(..) => DefKind::Use,
- ItemKind::ForeignMod(..) => DefKind::ForeignMod,
+ ItemKind::ForeignMod { .. } => DefKind::ForeignMod,
ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
ItemKind::Impl { .. } => DefKind::Impl,
},
}
}
+ pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
+ match self.find(id.hir_id).unwrap() {
+ Node::ForeignItem(item) => item,
+ _ => bug!(),
+ }
+ }
+
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> {
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap()
}
pub fn body_param_names(&self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
self.body(id).params.iter().map(|arg| match arg.pat.kind {
PatKind::Binding(_, _, ident, _) => ident,
- _ => Ident::new(kw::Invalid, rustc_span::DUMMY_SP),
+ _ => Ident::new(kw::Empty, rustc_span::DUMMY_SP),
})
}
for id in &module.impl_items {
visitor.visit_impl_item(self.expect_impl_item(id.hir_id));
}
+
+ for id in &module.foreign_items {
+ visitor.visit_foreign_item(self.expect_foreign_item(id.hir_id));
+ }
}
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
let mut scope = id;
loop {
scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID);
- if scope == CRATE_HIR_ID {
- return CRATE_HIR_ID;
- }
- match self.get(scope) {
- Node::Block(_) => {}
- _ => break,
+ if scope == CRATE_HIR_ID || !matches!(self.get(scope), Node::Block(_)) {
+ return scope;
}
}
- scope
}
pub fn get_parent_did(&self, id: HirId) -> LocalDefId {
let parent = self.get_parent_item(hir_id);
if let Some(entry) = self.find_entry(parent) {
if let Entry {
- node: Node::Item(Item { kind: ItemKind::ForeignMod(ref nm), .. }), ..
+ node: Node::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }),
+ ..
} = entry
{
- return nm.abi;
+ return *abi;
}
}
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
self.impl_item(id)
}
+
+ fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
+ self.foreign_item(id)
+ }
}
trait Named {
ItemKind::Const(..) => "const",
ItemKind::Fn(..) => "fn",
ItemKind::Mod(..) => "mod",
- ItemKind::ForeignMod(..) => "foreign mod",
+ ItemKind::ForeignMod { .. } => "foreign mod",
ItemKind::GlobalAsm(..) => "global asm",
ItemKind::TyAlias(..) => "ty",
ItemKind::OpaqueTy(..) => "opaque type",