diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index 5d4d17b6164..112a10b5bc3 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -139,6 +139,13 @@ impl RangeIndex for LineIndices {} impl Add for LineIndices { fn add(&self, other: &LineIndices) -> LineIndices { + // TODO: use debug_assert! after rustc upgrade + if cfg!(not(ndebug)) { + assert!(other.fragment_index == num::zero() || other.glyph_index == num::zero(), + "Attempted to add {} to {}. Both the fragment_index and \ + glyph_index of the RHS are non-zero. This probably \ + was a mistake!", self, other); + } LineIndices { fragment_index: self.fragment_index + other.fragment_index, glyph_index: self.glyph_index + other.glyph_index, @@ -148,6 +155,13 @@ impl Add for LineIndices { impl Sub for LineIndices { fn sub(&self, other: &LineIndices) -> LineIndices { + // TODO: use debug_assert! after rustc upgrade + if cfg!(not(ndebug)) { + assert!(other.fragment_index == num::zero() || other.glyph_index == num::zero(), + "Attempted to subtract {} from {}. Both the \ + fragment_index and glyph_index of the RHS are non-zero. \ + This probably was a mistake!", self, other); + } LineIndices { fragment_index: self.fragment_index - other.fragment_index, glyph_index: self.glyph_index - other.glyph_index, @@ -157,6 +171,13 @@ impl Sub for LineIndices { impl Neg for LineIndices { fn neg(&self) -> LineIndices { + // TODO: use debug_assert! after rustc upgrade + if cfg!(not(ndebug)) { + assert!(self.fragment_index == num::zero() || self.glyph_index == num::zero(), + "Attempted to negate {}. Both the fragment_index and \ + glyph_index are non-zero. This probably was a mistake!", + self); + } LineIndices { fragment_index: -self.fragment_index, glyph_index: -self.glyph_index,