about summary refs log tree commit diff
path: root/src/librustc/mir/interpret/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc/mir/interpret/mod.rs')
-rw-r--r--src/librustc/mir/interpret/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs
index e925d7429ff..6c31d54e081 100644
--- a/src/librustc/mir/interpret/mod.rs
+++ b/src/librustc/mir/interpret/mod.rs
@@ -470,6 +470,14 @@ impl<'tcx> AllocMap<'tcx> {
         }
     }
 
+    /// Panics if the `AllocId` does not refer to a function
+    pub fn unwrap_fn(&self, id: AllocId) -> Instance<'tcx> {
+        match self.get(id) {
+            Some(GlobalAlloc::Function(instance)) => instance,
+            _ => bug!("expected allocation ID {} to point to a function", id),
+        }
+    }
+
     /// Freezes an `AllocId` created with `reserve` by pointing it at an `Allocation`. Trying to
     /// call this function twice, even with the same `Allocation` will ICE the compiler.
     pub fn set_alloc_id_memory(&mut self, id: AllocId, mem: &'tcx Allocation) {