From edee094d3c3662f8c045c19e9705d32f7b652bb1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 29 Sep 2017 18:41:38 -0700 Subject: Introduce VarId for ids pointing to Var --- src/ir/context.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 for usize { fn from(id: ItemId) -> usize { id.0 -- cgit v1.2.3