Skip to content

Commit 4fc497f

Browse files
committed
Assume i128 support
1 parent e7fdddb commit 4fc497f

File tree

19 files changed

+29
-160
lines changed

19 files changed

+29
-160
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- uses: dtolnay/rust-toolchain@stable
4545
with:
4646
target: thumbv6m-none-eabi
47-
- run: cargo build --target thumbv6m-none-eabi --no-default-features --features i128
47+
- run: cargo build --target thumbv6m-none-eabi --no-default-features
4848
- run: cargo build --target thumbv6m-none-eabi --no-default-features --features libm
4949

5050
fmt:

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ libm = { version = "0.2.0", optional = true }
2424
[features]
2525
default = ["std"]
2626
std = []
27+
28+
# vestigial features, now always in effect
2729
i128 = []
2830

2931
[build-dependencies]

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ The `FloatCore` trait is always available. `MulAdd` and `MulAddAssign` for `f32
3535
and `f64` also require `std` or `libm`, as do implementations of signed and floating-
3636
point exponents in `Pow`.
3737

38-
Implementations for `i128` and `u128` are only available with Rust 1.26 and
39-
later. The build script automatically detects this, but you can make it
40-
mandatory by enabling the `i128` crate feature.
41-
4238
## Releases
4339

4440
Release notes are available in [RELEASES.md](RELEASES.md).

build.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ use std::env;
33
fn main() {
44
let ac = autocfg::new();
55

6-
// If the "i128" feature is explicity requested, don't bother probing for it.
7-
// It will still cause a build error if that was set improperly.
8-
if env::var_os("CARGO_FEATURE_I128").is_some() || ac.probe_type("i128") {
9-
autocfg::emit("has_i128");
10-
}
11-
126
ac.emit_expression_cfg(
137
"unsafe { 1f64.to_int_unchecked::<i32>() }",
148
"has_to_int_unchecked",

ci/test_full.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ if ! check_version $MSRV ; then
2828
fi
2929

3030
FEATURES=()
31-
check_version 1.26 && FEATURES+=(i128)
3231
check_version 1.27 && FEATURES+=(libm)
3332
echo "Testing supported features: ${FEATURES[*]}"
3433

src/bounds.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use core::num::Wrapping;
22
use core::{f32, f64};
3-
#[cfg(has_i128)]
4-
use core::{i128, u128};
5-
use core::{i16, i32, i64, i8, isize};
6-
use core::{u16, u32, u64, u8, usize};
3+
use core::{i128, i16, i32, i64, i8, isize};
4+
use core::{u128, u16, u32, u64, u8, usize};
75

86
/// Numbers which have upper and lower bounds
97
pub trait Bounded {
@@ -61,15 +59,13 @@ bounded_impl!(u8, u8::MIN, u8::MAX);
6159
bounded_impl!(u16, u16::MIN, u16::MAX);
6260
bounded_impl!(u32, u32::MIN, u32::MAX);
6361
bounded_impl!(u64, u64::MIN, u64::MAX);
64-
#[cfg(has_i128)]
6562
bounded_impl!(u128, u128::MIN, u128::MAX);
6663

6764
bounded_impl!(isize, isize::MIN, isize::MAX);
6865
bounded_impl!(i8, i8::MIN, i8::MAX);
6966
bounded_impl!(i16, i16::MIN, i16::MAX);
7067
bounded_impl!(i32, i32::MIN, i32::MAX);
7168
bounded_impl!(i64, i64::MIN, i64::MAX);
72-
#[cfg(has_i128)]
7369
bounded_impl!(i128, i128::MIN, i128::MAX);
7470

7571
impl<T: Bounded> Bounded for Wrapping<T> {
@@ -130,7 +126,6 @@ fn wrapping_bounded() {
130126
test_wrapping_bounded!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
131127
}
132128

133-
#[cfg(has_i128)]
134129
#[test]
135130
fn wrapping_bounded_i128() {
136131
macro_rules! test_wrapping_bounded {

src/cast.rs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use core::mem::size_of;
22
use core::num::Wrapping;
33
use core::{f32, f64};
4-
#[cfg(has_i128)]
5-
use core::{i128, u128};
6-
use core::{i16, i32, i64, i8, isize};
7-
use core::{u16, u32, u64, u8, usize};
4+
use core::{i128, i16, i32, i64, i8, isize};
5+
use core::{u128, u16, u32, u64, u8, usize};
86

97
/// A generic trait for converting a value to a number.
108
///
@@ -53,12 +51,9 @@ pub trait ToPrimitive {
5351
/// represented by an `i128` (`i64` under the default implementation), then
5452
/// `None` is returned.
5553
///
56-
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
57-
///
5854
/// The default implementation converts through `to_i64()`. Types implementing
5955
/// this trait should override this method if they can represent a greater range.
6056
#[inline]
61-
#[cfg(has_i128)]
6257
fn to_i128(&self) -> Option<i128> {
6358
self.to_i64().map(From::from)
6459
}
@@ -99,12 +94,9 @@ pub trait ToPrimitive {
9994
/// represented by a `u128` (`u64` under the default implementation), then
10095
/// `None` is returned.
10196
///
102-
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
103-
///
10497
/// The default implementation converts through `to_u64()`. Types implementing
10598
/// this trait should override this method if they can represent a greater range.
10699
#[inline]
107-
#[cfg(has_i128)]
108100
fn to_u128(&self) -> Option<u128> {
109101
self.to_u64().map(From::from)
110102
}
@@ -173,7 +165,6 @@ macro_rules! impl_to_primitive_int {
173165
fn to_i16 -> i16;
174166
fn to_i32 -> i32;
175167
fn to_i64 -> i64;
176-
#[cfg(has_i128)]
177168
fn to_i128 -> i128;
178169
}
179170

@@ -183,7 +174,6 @@ macro_rules! impl_to_primitive_int {
183174
fn to_u16 -> u16;
184175
fn to_u32 -> u32;
185176
fn to_u64 -> u64;
186-
#[cfg(has_i128)]
187177
fn to_u128 -> u128;
188178
}
189179

@@ -204,7 +194,6 @@ impl_to_primitive_int!(i8);
204194
impl_to_primitive_int!(i16);
205195
impl_to_primitive_int!(i32);
206196
impl_to_primitive_int!(i64);
207-
#[cfg(has_i128)]
208197
impl_to_primitive_int!(i128);
209198

210199
macro_rules! impl_to_primitive_uint_to_int {
@@ -246,7 +235,6 @@ macro_rules! impl_to_primitive_uint {
246235
fn to_i16 -> i16;
247236
fn to_i32 -> i32;
248237
fn to_i64 -> i64;
249-
#[cfg(has_i128)]
250238
fn to_i128 -> i128;
251239
}
252240

@@ -256,7 +244,6 @@ macro_rules! impl_to_primitive_uint {
256244
fn to_u16 -> u16;
257245
fn to_u32 -> u32;
258246
fn to_u64 -> u64;
259-
#[cfg(has_i128)]
260247
fn to_u128 -> u128;
261248
}
262249

@@ -277,7 +264,6 @@ impl_to_primitive_uint!(u8);
277264
impl_to_primitive_uint!(u16);
278265
impl_to_primitive_uint!(u32);
279266
impl_to_primitive_uint!(u64);
280-
#[cfg(has_i128)]
281267
impl_to_primitive_uint!(u128);
282268

283269
macro_rules! impl_to_primitive_float_to_float {
@@ -373,7 +359,6 @@ macro_rules! impl_to_primitive_float {
373359
fn to_i16 -> i16;
374360
fn to_i32 -> i32;
375361
fn to_i64 -> i64;
376-
#[cfg(has_i128)]
377362
fn to_i128 -> i128;
378363
}
379364

@@ -383,7 +368,6 @@ macro_rules! impl_to_primitive_float {
383368
fn to_u16 -> u16;
384369
fn to_u32 -> u32;
385370
fn to_u64 -> u64;
386-
#[cfg(has_i128)]
387371
fn to_u128 -> u128;
388372
}
389373

@@ -444,12 +428,9 @@ pub trait FromPrimitive: Sized {
444428
/// Converts an `i128` to return an optional value of this type. If the
445429
/// value cannot be represented by this type, then `None` is returned.
446430
///
447-
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
448-
///
449431
/// The default implementation converts through `from_i64()`. Types implementing
450432
/// this trait should override this method if they can represent a greater range.
451433
#[inline]
452-
#[cfg(has_i128)]
453434
fn from_i128(n: i128) -> Option<Self> {
454435
n.to_i64().and_then(FromPrimitive::from_i64)
455436
}
@@ -489,12 +470,9 @@ pub trait FromPrimitive: Sized {
489470
/// Converts an `u128` to return an optional value of this type. If the
490471
/// value cannot be represented by this type, then `None` is returned.
491472
///
492-
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
493-
///
494473
/// The default implementation converts through `from_u64()`. Types implementing
495474
/// this trait should override this method if they can represent a greater range.
496475
#[inline]
497-
#[cfg(has_i128)]
498476
fn from_u128(n: u128) -> Option<Self> {
499477
n.to_u64().and_then(FromPrimitive::from_u64)
500478
}
@@ -545,7 +523,6 @@ macro_rules! impl_from_primitive {
545523
fn from_i64(n: i64) -> Option<$T> {
546524
n.$to_ty()
547525
}
548-
#[cfg(has_i128)]
549526
#[inline]
550527
fn from_i128(n: i128) -> Option<$T> {
551528
n.$to_ty()
@@ -571,7 +548,6 @@ macro_rules! impl_from_primitive {
571548
fn from_u64(n: u64) -> Option<$T> {
572549
n.$to_ty()
573550
}
574-
#[cfg(has_i128)]
575551
#[inline]
576552
fn from_u128(n: u128) -> Option<$T> {
577553
n.$to_ty()
@@ -594,14 +570,12 @@ impl_from_primitive!(i8, to_i8);
594570
impl_from_primitive!(i16, to_i16);
595571
impl_from_primitive!(i32, to_i32);
596572
impl_from_primitive!(i64, to_i64);
597-
#[cfg(has_i128)]
598573
impl_from_primitive!(i128, to_i128);
599574
impl_from_primitive!(usize, to_usize);
600575
impl_from_primitive!(u8, to_u8);
601576
impl_from_primitive!(u16, to_u16);
602577
impl_from_primitive!(u32, to_u32);
603578
impl_from_primitive!(u64, to_u64);
604-
#[cfg(has_i128)]
605579
impl_from_primitive!(u128, to_u128);
606580
impl_from_primitive!(f32, to_f32);
607581
impl_from_primitive!(f64, to_f64);
@@ -623,15 +597,13 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
623597
fn to_i16 -> i16;
624598
fn to_i32 -> i32;
625599
fn to_i64 -> i64;
626-
#[cfg(has_i128)]
627600
fn to_i128 -> i128;
628601

629602
fn to_usize -> usize;
630603
fn to_u8 -> u8;
631604
fn to_u16 -> u16;
632605
fn to_u32 -> u32;
633606
fn to_u64 -> u64;
634-
#[cfg(has_i128)]
635607
fn to_u128 -> u128;
636608

637609
fn to_f32 -> f32;
@@ -656,15 +628,13 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
656628
fn from_i16(i16);
657629
fn from_i32(i32);
658630
fn from_i64(i64);
659-
#[cfg(has_i128)]
660631
fn from_i128(i128);
661632

662633
fn from_usize(usize);
663634
fn from_u8(u8);
664635
fn from_u16(u16);
665636
fn from_u32(u32);
666637
fn from_u64(u64);
667-
#[cfg(has_i128)]
668638
fn from_u128(u128);
669639

670640
fn from_f32(f32);
@@ -722,14 +692,12 @@ impl_num_cast!(u8, to_u8);
722692
impl_num_cast!(u16, to_u16);
723693
impl_num_cast!(u32, to_u32);
724694
impl_num_cast!(u64, to_u64);
725-
#[cfg(has_i128)]
726695
impl_num_cast!(u128, to_u128);
727696
impl_num_cast!(usize, to_usize);
728697
impl_num_cast!(i8, to_i8);
729698
impl_num_cast!(i16, to_i16);
730699
impl_num_cast!(i32, to_i32);
731700
impl_num_cast!(i64, to_i64);
732-
#[cfg(has_i128)]
733701
impl_num_cast!(i128, to_i128);
734702
impl_num_cast!(isize, to_isize);
735703
impl_num_cast!(f32, to_f32);
@@ -787,10 +755,8 @@ macro_rules! impl_as_primitive {
787755
)*};
788756
($T: ty => { $( $U: ty ),* } ) => {
789757
impl_as_primitive!(@ $T => { $( $U ),* });
790-
impl_as_primitive!(@ $T => { u8, u16, u32, u64, usize });
791-
impl_as_primitive!(@ $T => #[cfg(has_i128)] impl u128);
792-
impl_as_primitive!(@ $T => { i8, i16, i32, i64, isize });
793-
impl_as_primitive!(@ $T => #[cfg(has_i128)] impl i128);
758+
impl_as_primitive!(@ $T => { u8, u16, u32, u64, u128, usize });
759+
impl_as_primitive!(@ $T => { i8, i16, i32, i64, i128, isize });
794760
};
795761
}
796762

@@ -802,9 +768,7 @@ impl_as_primitive!(u32 => { f32, f64 });
802768
impl_as_primitive!(i32 => { f32, f64 });
803769
impl_as_primitive!(u64 => { f32, f64 });
804770
impl_as_primitive!(i64 => { f32, f64 });
805-
#[cfg(has_i128)]
806771
impl_as_primitive!(u128 => { f32, f64 });
807-
#[cfg(has_i128)]
808772
impl_as_primitive!(i128 => { f32, f64 });
809773
impl_as_primitive!(usize => { f32, f64 });
810774
impl_as_primitive!(isize => { f32, f64 });

src/identities.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ zero_impl!(u8, 0);
4848
zero_impl!(u16, 0);
4949
zero_impl!(u32, 0);
5050
zero_impl!(u64, 0);
51-
#[cfg(has_i128)]
5251
zero_impl!(u128, 0);
5352

5453
zero_impl!(isize, 0);
5554
zero_impl!(i8, 0);
5655
zero_impl!(i16, 0);
5756
zero_impl!(i32, 0);
5857
zero_impl!(i64, 0);
59-
#[cfg(has_i128)]
6058
zero_impl!(i128, 0);
6159

6260
zero_impl!(f32, 0.0);
@@ -137,15 +135,13 @@ one_impl!(u8, 1);
137135
one_impl!(u16, 1);
138136
one_impl!(u32, 1);
139137
one_impl!(u64, 1);
140-
#[cfg(has_i128)]
141138
one_impl!(u128, 1);
142139

143140
one_impl!(isize, 1);
144141
one_impl!(i8, 1);
145142
one_impl!(i16, 1);
146143
one_impl!(i32, 1);
147144
one_impl!(i64, 1);
148-
#[cfg(has_i128)]
149145
one_impl!(i128, 1);
150146

151147
one_impl!(f32, 1.0);

src/int.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,12 @@ prim_int_impl!(u8, i8, u8);
500500
prim_int_impl!(u16, i16, u16);
501501
prim_int_impl!(u32, i32, u32);
502502
prim_int_impl!(u64, i64, u64);
503-
#[cfg(has_i128)]
504503
prim_int_impl!(u128, i128, u128);
505504
prim_int_impl!(usize, isize, usize);
506505
prim_int_impl!(i8, i8, u8);
507506
prim_int_impl!(i16, i16, u16);
508507
prim_int_impl!(i32, i32, u32);
509508
prim_int_impl!(i64, i64, u64);
510-
#[cfg(has_i128)]
511509
prim_int_impl!(i128, i128, u128);
512510
prim_int_impl!(isize, isize, usize);
513511

@@ -554,7 +552,6 @@ mod tests {
554552
}
555553

556554
#[test]
557-
#[cfg(has_i128)]
558555
pub fn reverse_bits_i128() {
559556
use core::i128;
560557

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ macro_rules! int_trait_impl {
172172
}
173173
)*)
174174
}
175-
int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
176-
#[cfg(has_i128)]
177-
int_trait_impl!(Num for u128 i128);
175+
int_trait_impl!(Num for usize u8 u16 u32 u64 u128);
176+
int_trait_impl!(Num for isize i8 i16 i32 i64 i128);
178177

179178
impl<T: Num> Num for Wrapping<T>
180179
where

0 commit comments

Comments
 (0)