Skip to content

Commit 3ef31e8

Browse files
committed
Introduce the FunctionId newtype for ids pointing to functions
1 parent 45db21b commit 3ef31e8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/ir/context.rs

+19
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,25 @@ item_id_newtype! {
154154
unchecked = as_var_id_unchecked;
155155
}
156156

157+
item_id_newtype! {
158+
/// An identifier for an `Item` whose `ItemKind` is known to be
159+
/// `ItemKind::Function`.
160+
pub struct FunctionId(ItemId)
161+
where
162+
/// Convert this `ItemId` into a `FunctionId` if its associated item is a function,
163+
/// otherwise return `None`.
164+
checked = as_function_id with is_function,
165+
166+
/// Convert this `ItemId` into a `FunctionId`.
167+
///
168+
/// If this `ItemId` does not point to a function, then panic.
169+
expected = expect_function_id,
170+
171+
/// Convert this `ItemId` into a `FunctionId` without actually checking whether
172+
/// this id actually points to a `Function`.
173+
unchecked = as_function_id_unchecked;
174+
}
175+
157176
impl From<ItemId> for usize {
158177
fn from(id: ItemId) -> usize {
159178
id.0

0 commit comments

Comments
 (0)