Skip to content

Commit

Permalink
Conditionally disable i128/u128 code based on the 'i128_type' feature
Browse files Browse the repository at this point in the history
There is an existing i128_type feature, enabled by default. Most code
that refers to i128 and u128 ignore it. Because of this, disabling
i128_type would cause compiler errors.

After this commit, no code referring to i128 or u128 will be enabled if
i128_type is disabled.
  • Loading branch information
dylanmckay committed Feb 22, 2018
1 parent 3c1d53d commit 6892809
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 52 deletions.
15 changes: 12 additions & 3 deletions core/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,17 +779,23 @@ mod impls {
}

partial_eq_impl! {
bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64
}

#[cfg(i128_type)]
partial_eq_impl! { u128 i128 }

macro_rules! eq_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for $t {}
)*)
}

eq_impl! { () bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
eq_impl! { () bool char usize u8 u16 u32 u64 isize i8 i16 i32 i64 }

#[cfg(i128_type)]
eq_impl! { u128 i128 }

macro_rules! partial_ord_impl {
($($t:ty)*) => ($(
Expand Down Expand Up @@ -878,7 +884,10 @@ mod impls {
}
}

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

#[cfg(i128_type)]
ord_impl! { u128 i128 }

#[unstable(feature = "never_type", issue = "35121")]
impl PartialEq for ! {
Expand Down
2 changes: 2 additions & 0 deletions core/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ default_impl! { u8, 0, "Returns the default value of `0`" }
default_impl! { u16, 0, "Returns the default value of `0`" }
default_impl! { u32, 0, "Returns the default value of `0`" }
default_impl! { u64, 0, "Returns the default value of `0`" }
#[cfg(i128_type)]
default_impl! { u128, 0, "Returns the default value of `0`" }

default_impl! { isize, 0, "Returns the default value of `0`" }
default_impl! { i8, 0, "Returns the default value of `0`" }
default_impl! { i16, 0, "Returns the default value of `0`" }
default_impl! { i32, 0, "Returns the default value of `0`" }
default_impl! { i64, 0, "Returns the default value of `0`" }
#[cfg(i128_type)]
default_impl! { i128, 0, "Returns the default value of `0`" }

default_impl! { f32, 0.0f32, "Returns the default value of `0.0`" }
Expand Down
9 changes: 8 additions & 1 deletion core/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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;
#[cfg(i128_type)]
fn to_u128(&self) -> u128;
}

Expand All @@ -40,10 +41,14 @@ 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 }
#[cfg(i128_type)]
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 }

#[cfg(i128_type)]
doit! { i128 u128 }

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

const DEC_DIGITS_LUT: &'static[u8] =
Expand Down Expand Up @@ -261,6 +267,7 @@ macro_rules! impl_Display {

impl_Display!(i8, u8, i16, u16, i32, u32: to_u32);
impl_Display!(i64, u64: to_u64);
#[cfg(i128_type)]
impl_Display!(i128, u128: to_u128);
#[cfg(target_pointer_width = "16")]
impl_Display!(isize, usize: to_u16);
Expand Down
8 changes: 8 additions & 0 deletions core/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ pub trait Hasher {
/// Writes a single `u128` into this hasher.
#[inline]
#[unstable(feature = "i128", issue = "35118")]
#[cfg(i128_type)]
fn write_u128(&mut self, i: u128) {
self.write(&unsafe { mem::transmute::<_, [u8; 16]>(i) })
}
Expand Down Expand Up @@ -348,6 +349,7 @@ pub trait Hasher {
/// Writes a single `i128` into this hasher.
#[inline]
#[unstable(feature = "i128", issue = "35118")]
#[cfg(i128_type)]
fn write_i128(&mut self, i: i128) {
self.write_u128(i as u128)
}
Expand Down Expand Up @@ -379,6 +381,7 @@ impl<'a, H: Hasher + ?Sized> Hasher for &'a mut H {
fn write_u64(&mut self, i: u64) {
(**self).write_u64(i)
}
#[cfg(i128_type)]
fn write_u128(&mut self, i: u128) {
(**self).write_u128(i)
}
Expand All @@ -397,6 +400,7 @@ impl<'a, H: Hasher + ?Sized> Hasher for &'a mut H {
fn write_i64(&mut self, i: i64) {
(**self).write_i64(i)
}
#[cfg(i128_type)]
fn write_i128(&mut self, i: i128) {
(**self).write_i128(i)
}
Expand Down Expand Up @@ -576,6 +580,10 @@ mod impls {
(i32, write_i32),
(i64, write_i64),
(isize, write_isize),
}

#[cfg(i128_type)]
impl_write! {
(u128, write_u128),
(i128, write_i128),
}
Expand Down
1 change: 1 addition & 0 deletions core/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ 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);
#[cfg(i128_type)]
step_impl_no_between!(u128 i128);

macro_rules! range_exact_iter_impl {
Expand Down
6 changes: 5 additions & 1 deletion core/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,11 @@ 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 }

#[cfg(i128_type)]
integer_sum_product! { i128 u128 }

float_sum_product! { f32 f64 }

/// An iterator adapter that produces output as long as the underlying
Expand Down
7 changes: 5 additions & 2 deletions core/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ impl_zeroable_for_pointer_types! {
}

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

#[cfg(i128_type)]
impl_zeroable_for_integer_types! { u128 i128 }

/// A wrapper type for raw pointers and integers that will never be
/// NULL or 0 that might allow certain optimizations.
#[lang = "non_zero"]
Expand Down
1 change: 1 addition & 0 deletions core/num/i128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

#![unstable(feature = "i128", issue="35118")]

#[cfg(i128_type)]
int_module! { i128, #[unstable(feature = "i128", issue="35118")] }

0 comments on commit 6892809

Please sign in to comment.