add helper to get DefId from MonoItem

This commit is contained in:
Rémy Rakic 2022-12-08 19:20:16 +00:00
parent fbf8b937b4
commit 74f4da44a5

View File

@ -200,6 +200,15 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::GlobalAsm(..) => LOCAL_CRATE,
}
}
/// Returns the item's `DefId`
pub fn def_id(&self) -> DefId {
match *self {
MonoItem::Fn(Instance { def, .. }) => def.def_id(),
MonoItem::Static(def_id) => def_id,
MonoItem::GlobalAsm(item_id) => item_id.owner_id.to_def_id(),
}
}
}
impl<'tcx> fmt::Display for MonoItem<'tcx> {