diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-29 18:41:38 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-10-02 12:18:44 -0700 |
commit | edee094d3c3662f8c045c19e9705d32f7b652bb1 (patch) | |
tree | 72962b29d85379f4e5eec8b0953c2db8b2446664 | |
parent | 9b294d3d8b6ae3332d111d2f29b16bac877a8fa8 (diff) |
Introduce VarId for ids pointing to Var
-rw-r--r-- | src/ir/context.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index 07731dde..5ebcfc28 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -135,6 +135,25 @@ item_id_newtype! { unchecked = as_module_id_unchecked; } +item_id_newtype! { + /// An identifier for an `Item` whose `ItemKind` is known to be + /// `ItemKind::Var`. + pub struct VarId(ItemId) + where + /// Convert this `ItemId` into a `VarId` if its associated item is a var, + /// otherwise return `None`. + checked = as_var_id with is_var, + + /// Convert this `ItemId` into a `VarId`. + /// + /// If this `ItemId` does not point to a var, then panic. + expected = expect_var_id, + + /// Convert this `ItemId` into a `VarId` without actually checking whether + /// this id actually points to a `Var`. + unchecked = as_var_id_unchecked; +} + impl From<ItemId> for usize { fn from(id: ItemId) -> usize { id.0 |