summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-10-02 11:57:29 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-10-02 12:19:05 -0700
commit3ef31e851e530d38f867c9063200576dee4494b0 (patch)
tree25aa798db01df5c6765669f348fb4c8196ac83be
parent45db21bfed19f318290c9c32edf42ba4a0a26ada (diff)
Introduce the `FunctionId` newtype for ids pointing to functions
-rw-r--r--src/ir/context.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 5ebcfc28..f9efbf05 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -154,6 +154,25 @@ item_id_newtype! {
unchecked = as_var_id_unchecked;
}
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Function`.
+ pub struct FunctionId(ItemId)
+ where
+ /// Convert this `ItemId` into a `FunctionId` if its associated item is a function,
+ /// otherwise return `None`.
+ checked = as_function_id with is_function,
+
+ /// Convert this `ItemId` into a `FunctionId`.
+ ///
+ /// If this `ItemId` does not point to a function, then panic.
+ expected = expect_function_id,
+
+ /// Convert this `ItemId` into a `FunctionId` without actually checking whether
+ /// this id actually points to a `Function`.
+ unchecked = as_function_id_unchecked;
+}
+
impl From<ItemId> for usize {
fn from(id: ItemId) -> usize {
id.0