diff options
| author | Rémy Rakic <remy.rakic+github@gmail.com> | 2022-12-08 19:20:16 +0000 |
|---|---|---|
| committer | Rémy Rakic <remy.rakic+github@gmail.com> | 2022-12-14 20:17:52 +0000 |
| commit | 74f4da44a5743e88ce2bbb76f585c02e67af83a1 (patch) | |
| tree | 32f83c059664da8c3f7a613696fcd570f0c6d437 /compiler/rustc_middle | |
| parent | fbf8b937b44d39ba03835b82ed7ea443321eb7c7 (diff) | |
| download | rust-74f4da44a5743e88ce2bbb76f585c02e67af83a1.tar.gz rust-74f4da44a5743e88ce2bbb76f585c02e67af83a1.zip | |
add helper to get DefId from MonoItem
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/mir/mono.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 15a24aa4ace..1e8d5f7eae8 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -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> { |
