rustc_serialize/
int_overflow.rs1pub trait DebugStrictAdd {
15 fn debug_strict_add(self, other: Self) -> Self;
17}
18
19macro_rules! impl_debug_strict_add {
20 ($( $ty:ty )*) => {
21 $(
22 impl DebugStrictAdd for $ty {
23 #[inline]
24 fn debug_strict_add(self, other: Self) -> Self {
25 if cfg!(debug_assertions) {
26 self + other
27 } else {
28 self.wrapping_add(other)
29 }
30 }
31 }
32 )*
33 };
34}
35
36pub trait DebugStrictSub {
38 fn debug_strict_sub(self, other: Self) -> Self;
40}
41
42macro_rules! impl_debug_strict_sub {
43 ($( $ty:ty )*) => {
44 $(
45 impl DebugStrictSub for $ty {
46 #[inline]
47 fn debug_strict_sub(self, other: Self) -> Self {
48 if cfg!(debug_assertions) {
49 self - other
50 } else {
51 self.wrapping_sub(other)
52 }
53 }
54 }
55 )*
56 };
57}
58
59impl DebugStrictAdd for u8 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for u16 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for u32 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for u64 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for u128 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for usize {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for i8 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for i16 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for i32 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for i64 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for i128 {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}
impl DebugStrictAdd for isize {
#[inline]
fn debug_strict_add(self, other: Self) -> Self {
if true { self + other } else { self.wrapping_add(other) }
}
}impl_debug_strict_add! {
60 u8 u16 u32 u64 u128 usize
61 i8 i16 i32 i64 i128 isize
62}
63
64impl DebugStrictSub for u8 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for u16 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for u32 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for u64 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for u128 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for usize {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for i8 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for i16 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for i32 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for i64 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for i128 {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}
impl DebugStrictSub for isize {
#[inline]
fn debug_strict_sub(self, other: Self) -> Self {
if true { self - other } else { self.wrapping_sub(other) }
}
}impl_debug_strict_sub! {
65 u8 u16 u32 u64 u128 usize
66 i8 i16 i32 i64 i128 isize
67}