mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add some debug assertions
This commit is contained in:
parent
f883c6238e
commit
fccc5d2071
1 changed files with 21 additions and 0 deletions
|
@ -139,6 +139,13 @@ impl RangeIndex for LineIndices {}
|
|||
|
||||
impl Add<LineIndices, LineIndices> 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<LineIndices, LineIndices> for LineIndices {
|
|||
|
||||
impl Sub<LineIndices, LineIndices> 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<LineIndices, LineIndices> for LineIndices {
|
|||
|
||||
impl Neg<LineIndices> 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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue