Skip to content

Commit

Permalink
Disable operations on 128-bit numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gergoerdi authored and shepmaster committed Apr 25, 2018
1 parent f9a3909 commit e39a823
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 55 deletions.
6 changes: 1 addition & 5 deletions src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ trait Int: PartialEq + PartialOrd + Div<Output=Self> + Rem<Output=Self> +
fn to_u16(&self) -> u16;
fn to_u32(&self) -> u32;
fn to_u64(&self) -> u64;
fn to_u128(&self) -> u128;
}

macro_rules! doit {
Expand All @@ -40,10 +39,9 @@ macro_rules! doit {
fn to_u16(&self) -> u16 { *self as u16 }
fn to_u32(&self) -> u32 { *self as u32 }
fn to_u64(&self) -> u64 { *self as u64 }
fn to_u128(&self) -> u128 { *self as u128 }
})*)
}
doit! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }

/// A type that represents a specific radix
#[doc(hidden)]
Expand Down Expand Up @@ -184,7 +182,6 @@ integer! { i8, u8 }
integer! { i16, u16 }
integer! { i32, u32 }
integer! { i64, u64 }
integer! { i128, u128 }

const DEC_DIGITS_LUT: &'static[u8] =
b"0001020304050607080910111213141516171819\
Expand Down Expand Up @@ -260,7 +257,6 @@ macro_rules! impl_Display {

impl_Display!(i8, u8, i16, u16, i32, u32: to_u32);
impl_Display!(i64, u64: to_u64);
impl_Display!(i128, u128: to_u128);
#[cfg(target_pointer_width = "16")]
impl_Display!(isize, usize: to_u16);
#[cfg(target_pointer_width = "32")]
Expand Down
1 change: 0 additions & 1 deletion src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ step_impl_signed!([i64: u64]);
// assume here that it is less than 64-bits.
#[cfg(not(target_pointer_width = "64"))]
step_impl_no_between!(u64 i64);
step_impl_no_between!(u128 i128);

macro_rules! range_exact_iter_impl {
($($t:ty)*) => ($(
Expand Down
2 changes: 1 addition & 1 deletion src/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ macro_rules! float_sum_product {
)*)
}

integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
integer_sum_product! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }
float_sum_product! { f32 f64 }

/// An iterator adapter that produces output as long as the underlying
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,12 @@ mod uint_macros;
#[path = "num/i16.rs"] pub mod i16;
#[path = "num/i32.rs"] pub mod i32;
#[path = "num/i64.rs"] pub mod i64;
#[path = "num/i128.rs"] pub mod i128;

#[path = "num/usize.rs"] pub mod usize;
#[path = "num/u8.rs"] pub mod u8;
#[path = "num/u16.rs"] pub mod u16;
#[path = "num/u32.rs"] pub mod u32;
#[path = "num/u64.rs"] pub mod u64;
#[path = "num/u128.rs"] pub mod u128;


#[macro_use]
pub mod num;
Expand Down
54 changes: 11 additions & 43 deletions src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ nonzero_integers! {
NonZeroU16(u16);
NonZeroU32(u32);
NonZeroU64(u64);
NonZeroU128(u128);
NonZeroUsize(usize);
}

Expand All @@ -114,7 +113,6 @@ nonzero_integers! {
NonZeroI16(i16);
NonZeroI32(i32);
NonZeroI64(i64);
NonZeroI128(i128);
NonZeroIsize(isize);
}

Expand Down Expand Up @@ -1940,12 +1938,6 @@ impl i64 {
int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "" }
}

#[lang = "i128"]
impl i128 {
int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728,
170141183460469231731687303715884105727, "", "" }
}

#[cfg(target_pointer_width = "16")]
#[lang = "isize"]
impl isize {
Expand Down Expand Up @@ -4030,11 +4022,6 @@ impl u64 {
uint_impl! { u64, u64, 64, 18446744073709551615, "", "" }
}

#[lang = "u128"]
impl u128 {
uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, "", "" }
}

#[cfg(target_pointer_width = "16")]
#[lang = "usize"]
impl usize {
Expand Down Expand Up @@ -4168,7 +4155,7 @@ macro_rules! from_str_radix_int_impl {
}
)*}
}
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
from_str_radix_int_impl! { isize i8 i16 i32 i64 usize u8 u16 u32 u64 }

/// The error type returned when a checked integral type conversion fails.
#[unstable(feature = "try_from", issue = "33417")]
Expand Down Expand Up @@ -4269,30 +4256,25 @@ macro_rules! rev {
try_from_upper_bounded!(u16, u8);
try_from_upper_bounded!(u32, u16, u8);
try_from_upper_bounded!(u64, u32, u16, u8);
try_from_upper_bounded!(u128, u64, u32, u16, u8);

try_from_both_bounded!(i16, i8);
try_from_both_bounded!(i32, i16, i8);
try_from_both_bounded!(i64, i32, i16, i8);
try_from_both_bounded!(i128, i64, i32, i16, i8);

// unsigned-to-signed
try_from_upper_bounded!(u8, i8);
try_from_upper_bounded!(u16, i8, i16);
try_from_upper_bounded!(u32, i8, i16, i32);
try_from_upper_bounded!(u64, i8, i16, i32, i64);
try_from_upper_bounded!(u128, i8, i16, i32, i64, i128);

// signed-to-unsigned
try_from_lower_bounded!(i8, u8, u16, u32, u64, u128);
try_from_lower_bounded!(i16, u16, u32, u64, u128);
try_from_lower_bounded!(i32, u32, u64, u128);
try_from_lower_bounded!(i64, u64, u128);
try_from_lower_bounded!(i128, u128);
try_from_lower_bounded!(i8, u8, u16, u32, u64);
try_from_lower_bounded!(i16, u16, u32, u64);
try_from_lower_bounded!(i32, u32, u64);
try_from_lower_bounded!(i64, u64);
try_from_both_bounded!(i16, u8);
try_from_both_bounded!(i32, u16, u8);
try_from_both_bounded!(i64, u32, u16, u8);
try_from_both_bounded!(i128, u64, u32, u16, u8);

// usize/isize
try_from_upper_bounded!(usize, isize);
Expand All @@ -4309,9 +4291,9 @@ mod ptr_try_from_impls {
use convert::TryFrom;

// Fallible across platfoms, only implementation differs
try_from_lower_bounded!(isize, u16, u32, u64, u128);
try_from_lower_bounded!(isize, u16, u32, u64);
rev!(try_from_lower_bounded, usize, i8, i16);
rev!(try_from_both_bounded, usize, i32, i64, i128);
rev!(try_from_both_bounded, usize, i32, i64);
}

#[cfg(target_pointer_width = "32")]
Expand All @@ -4321,9 +4303,9 @@ mod ptr_try_from_impls {

// Fallible across platfoms, only implementation differs
try_from_both_bounded!(isize, u16);
try_from_lower_bounded!(isize, u32, u64, u128);
try_from_lower_bounded!(isize, u32, u64);
rev!(try_from_lower_bounded, usize, i8, i16, i32);
rev!(try_from_both_bounded, usize, i64, i128);
rev!(try_from_both_bounded, usize, i64);
}

#[cfg(target_pointer_width = "64")]
Expand All @@ -4333,9 +4315,8 @@ mod ptr_try_from_impls {

// Fallible across platfoms, only implementation differs
try_from_both_bounded!(isize, u16, u32);
try_from_lower_bounded!(isize, u64, u128);
try_from_lower_bounded!(isize, u64);
rev!(try_from_lower_bounded, usize, i8, i16, i32, i64);
rev!(try_from_both_bounded, usize, i128);
}

#[doc(hidden)]
Expand Down Expand Up @@ -4370,7 +4351,7 @@ macro_rules! doit {
}
})*)
}
doit! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
doit! { i8 i16 i32 isize u8 u16 u32 usize }

fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, ParseIntError> {
use self::IntErrorKind::*;
Expand Down Expand Up @@ -4511,39 +4492,27 @@ macro_rules! impl_from {
impl_from! { u8, u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, u128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u8, usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u16, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u16, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u16, u128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u32, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u32, u128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u64, u128, #[stable(feature = "i128", since = "1.26.0")] }

// Signed -> Signed
impl_from! { i8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i8, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { i8, isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i16, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { i32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { i32, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { i64, i128, #[stable(feature = "i128", since = "1.26.0")] }

// Unsigned -> Signed
impl_from! { u8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u8, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u16, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
impl_from! { u32, i128, #[stable(feature = "i128", since = "1.26.0")] }
impl_from! { u64, i128, #[stable(feature = "i128", since = "1.26.0")] }

// The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX
// which imply that pointer-sized integers must be at least 16 bits:
Expand All @@ -4558,7 +4527,6 @@ impl_from! { i16, isize, #[stable(feature = "lossless_iusize_conv", since = "1.2
// https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf
// http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf


// Note: integers can only be represented with full precision in a float if
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
// Lossy float conversions are not implemented at this time.
Expand Down
4 changes: 2 additions & 2 deletions src/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ macro_rules! wrapping_impl {
)*)
}

wrapping_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
wrapping_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }

macro_rules! wrapping_int_impl {
($($t:ty)*) => ($(
Expand Down Expand Up @@ -628,7 +628,7 @@ macro_rules! wrapping_int_impl {
)*)
}

wrapping_int_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
wrapping_int_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }


mod shift_max {
Expand Down

0 comments on commit e39a823

Please sign in to comment.