diff --git a/src/types.rs b/src/types.rs index ff053524..fd4a7736 100644 --- a/src/types.rs +++ b/src/types.rs @@ -212,14 +212,15 @@ impl ops::Add for Var { type Output = Var; fn add(self, rhs: u32) -> Self::Output { - Var { - idx: self.idx + rhs, - } + let idx = self.idx + rhs; + debug_assert!(idx <= Var::MAX_IDX); + Var { idx } } } impl ops::AddAssign for Var { fn add_assign(&mut self, rhs: u32) { + debug_assert!(self.idx + rhs <= Var::MAX_IDX); self.idx += rhs; } }