Skip to content

Commit a90d4a6

Browse files
authored
Merge pull request #310 from cuviper/msrv-1.60
Use namespaced-features to safely bump to MSRV 1.60
2 parents eb20b40 + ca42b4e commit a90d4a6

File tree

14 files changed

+23
-273
lines changed

14 files changed

+23
-273
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
rust: [
12-
1.31.0, # MSRV
13-
1.35.0, # has_copysign
14-
1.37.0, # has_reverse_bits
15-
1.38.0, # has_div_euclid
16-
1.44.0, # has_to_int_unchecked
17-
1.46.0, # has_leading_trailing_ones
18-
1.53.0, # has_is_subnormal
12+
1.60.0, # MSRV
1913
1.62.0, # has_total_cmp
2014
stable,
2115
beta,

.github/workflows/master.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
rust: [1.31.0, stable]
16+
rust: [1.60.0, stable]
1717
steps:
1818
- uses: actions/checkout@v4
1919
- uses: actions/cache@v4

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
rust: [1.31.0, stable]
12+
rust: [1.60.0, stable]
1313
steps:
1414
- uses: actions/checkout@v4
1515
- uses: actions/cache@v4

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version = "0.2.18"
1212
readme = "README.md"
1313
build = "build.rs"
1414
exclude = ["/ci/*", "/.github/*"]
15-
edition = "2018"
16-
rust-version = "1.31"
15+
edition = "2021"
16+
rust-version = "1.60"
1717

1818
[package.metadata.docs.rs]
1919
features = ["std"]
@@ -24,6 +24,7 @@ libm = { version = "0.2.0", optional = true }
2424

2525
[features]
2626
default = ["std"]
27+
libm = ["dep:libm"]
2728
std = []
2829

2930
# vestigial features, now always in effect

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-traits.svg)](https://crates.io/crates/num-traits)
44
[![documentation](https://docs.rs/num-traits/badge.svg)](https://docs.rs/num-traits)
5-
[![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
5+
[![minimum rustc 1.60](https://img.shields.io/badge/rustc-1.60+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
66
[![build status](https://github.com/rust-num/num-traits/workflows/master/badge.svg)](https://github.com/rust-num/num-traits/actions)
77

88
Numeric traits for generic mathematics in Rust.
@@ -40,7 +40,7 @@ Release notes are available in [RELEASES.md](RELEASES.md).
4040

4141
## Compatibility
4242

43-
The `num-traits` crate is tested for rustc 1.31 and greater.
43+
The `num-traits` crate is tested for rustc 1.60 and greater.
4444

4545
## License
4646

build.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
1-
use std::env;
2-
31
fn main() {
42
let ac = autocfg::new();
53

6-
ac.emit_expression_cfg(
7-
"unsafe { 1f64.to_int_unchecked::<i32>() }",
8-
"has_to_int_unchecked",
9-
);
10-
11-
ac.emit_expression_cfg("1u32.reverse_bits()", "has_reverse_bits");
12-
ac.emit_expression_cfg("1u32.trailing_ones()", "has_leading_trailing_ones");
13-
ac.emit_expression_cfg("1u32.div_euclid(1u32)", "has_div_euclid");
14-
15-
if env::var_os("CARGO_FEATURE_STD").is_some() {
16-
ac.emit_expression_cfg("1f64.copysign(-1f64)", "has_copysign");
17-
}
18-
ac.emit_expression_cfg("1f64.is_subnormal()", "has_is_subnormal");
19-
ac.emit_expression_cfg("1f64.total_cmp(&2f64)", "has_total_cmp");
20-
21-
ac.emit_expression_cfg("1u32.to_ne_bytes()", "has_int_to_from_bytes");
22-
ac.emit_expression_cfg("3.14f64.to_ne_bytes()", "has_float_to_from_bytes");
4+
ac.emit_expression_cfg("1f64.total_cmp(&2f64)", "has_total_cmp"); // 1.62
235

246
autocfg::rerun_path("build.rs");
257
}

ci/rustup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
set -ex
66

77
ci=$(dirname $0)
8-
for version in 1.31.0 1.35.0 1.37.0 1.38.0 1.44.0 1.46.0 1.53.0 1.62.0 stable beta nightly; do
8+
for version in 1.60.0 1.62.0 stable beta nightly; do
99
rustup run "$version" "$ci/test_full.sh"
1010
done

ci/test_full.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
CRATE=num-traits
6-
MSRV=1.31
6+
MSRV=1.60
77

88
get_rust_version() {
99
local array=($(rustc --version));
@@ -32,9 +32,6 @@ echo "Testing supported features: ${FEATURES[*]}"
3232

3333
cargo generate-lockfile
3434

35-
# libm 0.2.6 started using {float}::EPSILON
36-
check_version 1.43 || cargo update -p libm --precise 0.2.5
37-
3835
set -x
3936

4037
# test the default

src/cast.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ macro_rules! impl_to_primitive_float_to_float {
277277
)*}
278278
}
279279

280-
#[cfg(has_to_int_unchecked)]
281280
macro_rules! float_to_int_unchecked {
282281
// SAFETY: Must not be NaN or infinite; must be representable as the integer after truncating.
283282
// We already checked that the float is in the exclusive range `(MIN-1, MAX+1)`.
@@ -286,13 +285,6 @@ macro_rules! float_to_int_unchecked {
286285
};
287286
}
288287

289-
#[cfg(not(has_to_int_unchecked))]
290-
macro_rules! float_to_int_unchecked {
291-
($float:expr => $int:ty) => {
292-
$float as $int
293-
};
294-
}
295-
296288
macro_rules! impl_to_primitive_float_to_signed_int {
297289
($f:ident : $( $(#[$cfg:meta])* fn $method:ident -> $i:ident ; )*) => {$(
298290
#[inline]

src/float.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ impl FloatCore for f32 {
790790
Self::is_infinite(self) -> bool;
791791
Self::is_finite(self) -> bool;
792792
Self::is_normal(self) -> bool;
793+
Self::is_subnormal(self) -> bool;
793794
Self::classify(self) -> FpCategory;
794795
Self::is_sign_positive(self) -> bool;
795796
Self::is_sign_negative(self) -> bool;
@@ -800,11 +801,6 @@ impl FloatCore for f32 {
800801
Self::to_radians(self) -> Self;
801802
}
802803

803-
#[cfg(has_is_subnormal)]
804-
forward! {
805-
Self::is_subnormal(self) -> bool;
806-
}
807-
808804
#[cfg(feature = "std")]
809805
forward! {
810806
Self::floor(self) -> Self;
@@ -855,6 +851,7 @@ impl FloatCore for f64 {
855851
Self::is_infinite(self) -> bool;
856852
Self::is_finite(self) -> bool;
857853
Self::is_normal(self) -> bool;
854+
Self::is_subnormal(self) -> bool;
858855
Self::classify(self) -> FpCategory;
859856
Self::is_sign_positive(self) -> bool;
860857
Self::is_sign_negative(self) -> bool;
@@ -865,11 +862,6 @@ impl FloatCore for f64 {
865862
Self::to_radians(self) -> Self;
866863
}
867864

868-
#[cfg(has_is_subnormal)]
869-
forward! {
870-
Self::is_subnormal(self) -> bool;
871-
}
872-
873865
#[cfg(feature = "std")]
874866
forward! {
875867
Self::floor(self) -> Self;
@@ -1901,6 +1893,7 @@ macro_rules! float_impl_std {
19011893
Self::is_infinite(self) -> bool;
19021894
Self::is_finite(self) -> bool;
19031895
Self::is_normal(self) -> bool;
1896+
Self::is_subnormal(self) -> bool;
19041897
Self::classify(self) -> FpCategory;
19051898
Self::floor(self) -> Self;
19061899
Self::ceil(self) -> Self;
@@ -1944,17 +1937,8 @@ macro_rules! float_impl_std {
19441937
Self::asinh(self) -> Self;
19451938
Self::acosh(self) -> Self;
19461939
Self::atanh(self) -> Self;
1947-
}
1948-
1949-
#[cfg(has_copysign)]
1950-
forward! {
19511940
Self::copysign(self, sign: Self) -> Self;
19521941
}
1953-
1954-
#[cfg(has_is_subnormal)]
1955-
forward! {
1956-
Self::is_subnormal(self) -> bool;
1957-
}
19581942
}
19591943
};
19601944
}
@@ -1993,6 +1977,7 @@ macro_rules! float_impl_libm {
19931977
Self::is_infinite(self) -> bool;
19941978
Self::is_finite(self) -> bool;
19951979
Self::is_normal(self) -> bool;
1980+
Self::is_subnormal(self) -> bool;
19961981
Self::classify(self) -> FpCategory;
19971982
Self::is_sign_positive(self) -> bool;
19981983
Self::is_sign_negative(self) -> bool;
@@ -2003,11 +1988,6 @@ macro_rules! float_impl_libm {
20031988
Self::to_radians(self) -> Self;
20041989
}
20051990

2006-
#[cfg(has_is_subnormal)]
2007-
forward! {
2008-
Self::is_subnormal(self) -> bool;
2009-
}
2010-
20111991
forward! {
20121992
FloatCore::signum(self) -> Self;
20131993
FloatCore::powi(self, n: i32) -> Self;

src/int.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ macro_rules! prim_int_impl {
404404
<$T>::count_zeros(self)
405405
}
406406

407-
#[cfg(has_leading_trailing_ones)]
408407
#[inline]
409408
fn leading_ones(self) -> u32 {
410409
<$T>::leading_ones(self)
@@ -415,7 +414,6 @@ macro_rules! prim_int_impl {
415414
<$T>::leading_zeros(self)
416415
}
417416

418-
#[cfg(has_leading_trailing_ones)]
419417
#[inline]
420418
fn trailing_ones(self) -> u32 {
421419
<$T>::trailing_ones(self)
@@ -461,7 +459,6 @@ macro_rules! prim_int_impl {
461459
<$T>::swap_bytes(self)
462460
}
463461

464-
#[cfg(has_reverse_bits)]
465462
#[inline]
466463
fn reverse_bits(self) -> Self {
467464
<$T>::reverse_bits(self)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//!
1313
//! ## Compatibility
1414
//!
15-
//! The `num-traits` crate is tested for rustc 1.31 and greater.
15+
//! The `num-traits` crate is tested for rustc 1.60 and greater.
1616
1717
#![doc(html_root_url = "https://docs.rs/num-traits/0.2")]
1818
#![deny(unconditional_recursion)]

src/ops/bytes.rs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use core::borrow::{Borrow, BorrowMut};
22
use core::cmp::{Eq, Ord, PartialEq, PartialOrd};
33
use core::fmt::Debug;
44
use core::hash::Hash;
5-
#[cfg(not(has_int_to_from_bytes))]
6-
use core::mem::transmute;
75

86
pub trait NumBytes:
97
Debug
@@ -152,7 +150,6 @@ pub trait FromBytes: Sized {
152150

153151
macro_rules! float_to_from_bytes_impl {
154152
($T:ty, $L:expr) => {
155-
#[cfg(has_float_to_from_bytes)]
156153
impl ToBytes for $T {
157154
type Bytes = [u8; $L];
158155

@@ -172,7 +169,6 @@ macro_rules! float_to_from_bytes_impl {
172169
}
173170
}
174171

175-
#[cfg(has_float_to_from_bytes)]
176172
impl FromBytes for $T {
177173
type Bytes = [u8; $L];
178174

@@ -191,52 +187,11 @@ macro_rules! float_to_from_bytes_impl {
191187
<$T>::from_ne_bytes(*bytes)
192188
}
193189
}
194-
195-
#[cfg(not(has_float_to_from_bytes))]
196-
impl ToBytes for $T {
197-
type Bytes = [u8; $L];
198-
199-
#[inline]
200-
fn to_be_bytes(&self) -> Self::Bytes {
201-
ToBytes::to_be_bytes(&self.to_bits())
202-
}
203-
204-
#[inline]
205-
fn to_le_bytes(&self) -> Self::Bytes {
206-
ToBytes::to_le_bytes(&self.to_bits())
207-
}
208-
209-
#[inline]
210-
fn to_ne_bytes(&self) -> Self::Bytes {
211-
ToBytes::to_ne_bytes(&self.to_bits())
212-
}
213-
}
214-
215-
#[cfg(not(has_float_to_from_bytes))]
216-
impl FromBytes for $T {
217-
type Bytes = [u8; $L];
218-
219-
#[inline]
220-
fn from_be_bytes(bytes: &Self::Bytes) -> Self {
221-
Self::from_bits(FromBytes::from_be_bytes(bytes))
222-
}
223-
224-
#[inline]
225-
fn from_le_bytes(bytes: &Self::Bytes) -> Self {
226-
Self::from_bits(FromBytes::from_le_bytes(bytes))
227-
}
228-
229-
#[inline]
230-
fn from_ne_bytes(bytes: &Self::Bytes) -> Self {
231-
Self::from_bits(FromBytes::from_ne_bytes(bytes))
232-
}
233-
}
234190
};
235191
}
236192

237193
macro_rules! int_to_from_bytes_impl {
238194
($T:ty, $L:expr) => {
239-
#[cfg(has_int_to_from_bytes)]
240195
impl ToBytes for $T {
241196
type Bytes = [u8; $L];
242197

@@ -256,7 +211,6 @@ macro_rules! int_to_from_bytes_impl {
256211
}
257212
}
258213

259-
#[cfg(has_int_to_from_bytes)]
260214
impl FromBytes for $T {
261215
type Bytes = [u8; $L];
262216

@@ -275,46 +229,6 @@ macro_rules! int_to_from_bytes_impl {
275229
<$T>::from_ne_bytes(*bytes)
276230
}
277231
}
278-
279-
#[cfg(not(has_int_to_from_bytes))]
280-
impl ToBytes for $T {
281-
type Bytes = [u8; $L];
282-
283-
#[inline]
284-
fn to_be_bytes(&self) -> Self::Bytes {
285-
<$T as ToBytes>::to_ne_bytes(&<$T>::to_be(*self))
286-
}
287-
288-
#[inline]
289-
fn to_le_bytes(&self) -> Self::Bytes {
290-
<$T as ToBytes>::to_ne_bytes(&<$T>::to_le(*self))
291-
}
292-
293-
#[inline]
294-
fn to_ne_bytes(&self) -> Self::Bytes {
295-
unsafe { transmute(*self) }
296-
}
297-
}
298-
299-
#[cfg(not(has_int_to_from_bytes))]
300-
impl FromBytes for $T {
301-
type Bytes = [u8; $L];
302-
303-
#[inline]
304-
fn from_be_bytes(bytes: &Self::Bytes) -> Self {
305-
Self::from_be(<Self as FromBytes>::from_ne_bytes(bytes))
306-
}
307-
308-
#[inline]
309-
fn from_le_bytes(bytes: &Self::Bytes) -> Self {
310-
Self::from_le(<Self as FromBytes>::from_ne_bytes(bytes))
311-
}
312-
313-
#[inline]
314-
fn from_ne_bytes(bytes: &Self::Bytes) -> Self {
315-
unsafe { transmute(*bytes) }
316-
}
317-
}
318232
};
319233
}
320234

0 commit comments

Comments
 (0)