Skip to content

Commit 74f4da4

Browse files
committed
add helper to get DefId from MonoItem
1 parent fbf8b93 commit 74f4da4

File tree

1 file changed

+9
-0
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+9
-0
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ impl<'tcx> MonoItem<'tcx> {
200200
MonoItem::GlobalAsm(..) => LOCAL_CRATE,
201201
}
202202
}
203+
204+
/// Returns the item's `DefId`
205+
pub fn def_id(&self) -> DefId {
206+
match *self {
207+
MonoItem::Fn(Instance { def, .. }) => def.def_id(),
208+
MonoItem::Static(def_id) => def_id,
209+
MonoItem::GlobalAsm(item_id) => item_id.owner_id.to_def_id(),
210+
}
211+
}
203212
}
204213

205214
impl<'tcx> fmt::Display for MonoItem<'tcx> {

0 commit comments

Comments
 (0)