Skip to content

Commit

Permalink
Add description method to OwnerNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Feb 29, 2024
1 parent b0d3e04 commit f2a9356
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3347,6 +3347,20 @@ pub enum OwnerNode<'hir> {
}

impl<'hir> OwnerNode<'hir> {
pub fn descr(&self) -> &'static str {
match self {
OwnerNode::Item(item) => item.kind.descr(),
OwnerNode::ForeignItem(foreign_item) => match foreign_item.kind {
ForeignItemKind::Fn(_, _, _) => "function",
ForeignItemKind::Static(_, _) => "static",
ForeignItemKind::Type => "extern type",
},
OwnerNode::TraitItem(_) => "trait item",
OwnerNode::ImplItem(_) => "impl item",
OwnerNode::Crate(_) => "crate",
}
}

pub fn ident(&self) -> Option<Ident> {
match self {
OwnerNode::Item(Item { ident, .. })
Expand Down

0 comments on commit f2a9356

Please sign in to comment.