From 1691e4172f81424b593d891bbeae5682d11144f4 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Fri, 2 Aug 2019 17:25:22 +0200 Subject: [PATCH 1/4] Upgrade to Rand 0.7 This bumps the MSRV to 1.32 for the `rand` feature. `SmallRng` is not used for the tests anymore, since enabling the corresponding feature would force other crates to use the feature as well. --- Cargo.toml | 2 +- src/crand.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6bff2be..beadbec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ default-features = false [dependencies.rand] optional = true -version = "0.5" +version = "0.7" default-features = false [features] diff --git a/src/crand.rs b/src/crand.rs index 9e43974..651a896 100644 --- a/src/crand.rs +++ b/src/crand.rs @@ -42,8 +42,8 @@ where } #[cfg(test)] -fn test_rng() -> SmallRng { - SmallRng::from_seed([42; 16]) +fn test_rng() -> StdRng { + StdRng::from_seed([42; 32]) } #[test] From 85f6e98441344bf9e369ffc30cdf4a08d32b0e3e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 17 Jan 2020 14:52:26 -0800 Subject: [PATCH 2/4] Raise the MSRV to 1.31 --- .travis.yml | 4 +--- README.md | 8 ++++---- ci/rustup.sh | 2 +- ci/test_full.sh | 15 ++++++++------- src/lib.rs | 4 ++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f9702d..2c7378a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: rust sudo: false rust: - - 1.15.0 - - 1.22.0 # rand - - 1.26.0 # has_i128 - 1.31.0 # 2018! + - 1.32.0 # rand - stable - beta - nightly diff --git a/README.md b/README.md index 0536a2b..d569dd3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-complex.svg)](https://crates.io/crates/num-complex) [![documentation](https://docs.rs/num-complex/badge.svg)](https://docs.rs/num-complex) -![minimum rustc 1.15](https://img.shields.io/badge/rustc-1.15+-red.svg) +![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg) [![Travis status](https://travis-ci.org/rust-num/num-complex.svg?branch=master)](https://travis-ci.org/rust-num/num-complex) `Complex` numbers for Rust. @@ -13,7 +13,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -num-complex = "0.2" +num-complex = "0.3" ``` and this to your crate root: @@ -29,7 +29,7 @@ the default `std` feature. Use this in `Cargo.toml`: ```toml [dependencies.num-complex] -version = "0.2" +version = "0.3" default-features = false ``` @@ -47,4 +47,4 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-complex` crate is tested for rustc 1.15 and greater. +The `num-complex` crate is tested for rustc 1.31 and greater. diff --git a/ci/rustup.sh b/ci/rustup.sh index c5aea79..f7cf748 100755 --- a/ci/rustup.sh +++ b/ci/rustup.sh @@ -5,7 +5,7 @@ set -ex export TRAVIS_RUST_VERSION -for TRAVIS_RUST_VERSION in 1.15.0 1.22.0 1.26.0 stable beta nightly; do +for TRAVIS_RUST_VERSION in 1.31.0 1.32.0 stable beta nightly; do run="rustup run $TRAVIS_RUST_VERSION" $run cargo build --verbose $run $PWD/ci/test_full.sh diff --git a/ci/test_full.sh b/ci/test_full.sh index bf992d2..cd95543 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -4,13 +4,10 @@ set -ex echo Testing num-complex on rustc ${TRAVIS_RUST_VERSION} -FEATURES="std serde" -if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable|1.26.0|1.22.0)$ ]]; then - FEATURES="$FEATURES rand" -fi -if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable|1.26.0)$ ]]; then - FEATURES="$FEATURES i128" -fi +case "$TRAVIS_RUST_VERSION" in + 1.31.*) FEATURES="serde" ;; + *) FEATURES="serde rand" ;; +esac # num-complex should build and test everywhere. cargo build --verbose @@ -29,3 +26,7 @@ done # test all supported features together cargo build --features="$FEATURES" cargo test --features="$FEATURES" + +# test all supported features together with std +cargo build --features="std $FEATURES" +cargo test --features="std $FEATURES" diff --git a/src/lib.rs b/src/lib.rs index 46dc2e8..db23e3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,9 +12,9 @@ //! //! ## Compatibility //! -//! The `num-complex` crate is tested for rustc 1.15 and greater. +//! The `num-complex` crate is tested for rustc 1.31 and greater. -#![doc(html_root_url = "https://docs.rs/num-complex/0.2")] +#![doc(html_root_url = "https://docs.rs/num-complex/0.3")] #![no_std] #[cfg(any(test, feature = "std"))] From ccbbf7d1c171bcb0972ca3ed6e21c09aa664075b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 17 Jan 2020 14:59:30 -0800 Subject: [PATCH 3/4] Assume 128-bit integer support --- .travis.yml | 2 +- Cargo.toml | 2 +- README.md | 4 ---- build.rs | 8 -------- src/cast.rs | 4 ---- src/lib.rs | 3 --- src/pow.rs | 1 - 7 files changed, 2 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c7378a..a4650dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: before_script: - rustup target add $TARGET script: - - cargo build --verbose --target $TARGET --no-default-features --features i128,rand,serde + - cargo build --verbose --target $TARGET --no-default-features --features rand,serde - name: "rustfmt" rust: 1.31.0 before_script: diff --git a/Cargo.toml b/Cargo.toml index beadbec..2a583f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ features = ["std", "serde", "rand"] [dependencies.num-traits] version = "0.2.11" default-features = false +features = ["i128"] [dependencies.serde] optional = true @@ -35,7 +36,6 @@ default-features = false [features] default = ["std"] -i128 = ["num-traits/i128"] std = ["num-traits/std"] [build-dependencies] diff --git a/README.md b/README.md index d569dd3..cb143c8 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,6 @@ Features based on `Float` types are only available when `std` is enabled. Where possible, `FloatCore` is used instead. Formatting complex numbers only supports format width when `std` is enabled. -Implementations for `i128` and `u128` are only available with Rust 1.26 and -later. The build script automatically detects this, but you can make it -mandatory by enabling the `i128` crate feature. - ## Releases Release notes are available in [RELEASES.md](RELEASES.md). diff --git a/build.rs b/build.rs index 85e88b7..60d24cb 100644 --- a/build.rs +++ b/build.rs @@ -1,16 +1,8 @@ extern crate autocfg; -use std::env; - fn main() { let ac = autocfg::new(); - if ac.probe_type("i128") { - println!("cargo:rustc-cfg=has_i128"); - } else if env::var_os("CARGO_FEATURE_I128").is_some() { - panic!("i128 support was not detected!"); - } - // autocfg doesn't have a direct way to probe for `const fn` yet. if ac.probe_rustc_version(1, 31) { autocfg::emit("has_const_fn"); diff --git a/src/cast.rs b/src/cast.rs index ace981d..3162cfa 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -22,9 +22,7 @@ impl ToPrimitive for Complex { impl_to_primitive!(i16, to_i16); impl_to_primitive!(i32, to_i32); impl_to_primitive!(i64, to_i64); - #[cfg(has_i128)] impl_to_primitive!(u128, to_u128); - #[cfg(has_i128)] impl_to_primitive!(i128, to_i128); impl_to_primitive!(f32, to_f32); impl_to_primitive!(f64, to_f64); @@ -53,9 +51,7 @@ impl FromPrimitive for Complex { impl_from_primitive!(i16, from_i16); impl_from_primitive!(i32, from_i32); impl_from_primitive!(i64, from_i64); - #[cfg(has_i128)] impl_from_primitive!(u128, from_u128); - #[cfg(has_i128)] impl_from_primitive!(i128, from_i128); impl_from_primitive!(f32, from_f32); impl_from_primitive!(f64, from_f64); diff --git a/src/lib.rs b/src/lib.rs index db23e3b..1b8f4ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1086,9 +1086,6 @@ impl Rem for Complex { } } -#[cfg(not(has_i128))] -real_arithmetic!(usize, u8, u16, u32, u64, isize, i8, i16, i32, i64, f32, f64); -#[cfg(has_i128)] real_arithmetic!(usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64); /* constants */ diff --git a/src/pow.rs b/src/pow.rs index 2f6b5ba..4d8a170 100644 --- a/src/pow.rs +++ b/src/pow.rs @@ -76,7 +76,6 @@ pow_impl!(u16, i16); pow_impl!(u32, i32); pow_impl!(u64, i64); pow_impl!(usize, isize); -#[cfg(has_i128)] pow_impl!(u128, i128); // Note: we can't add `impl Pow for Complex` because new blanket impls are a From 69247ad12ee865892399e839d2be225260d24f2d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 17 Jan 2020 15:01:09 -0800 Subject: [PATCH 4/4] Assume const fn support --- Cargo.toml | 4 ---- build.rs | 12 ------------ src/lib.rs | 9 --------- 3 files changed, 25 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 2a583f9..21c7cd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ name = "num-complex" repository = "https://github.com/rust-num/num-complex" version = "0.3.0-pre" readme = "README.md" -build = "build.rs" exclude = ["/ci/*", "/.travis.yml", "/bors.toml"] publish = false @@ -37,6 +36,3 @@ default-features = false [features] default = ["std"] std = ["num-traits/std"] - -[build-dependencies] -autocfg = "1" diff --git a/build.rs b/build.rs deleted file mode 100644 index 60d24cb..0000000 --- a/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern crate autocfg; - -fn main() { - let ac = autocfg::new(); - - // autocfg doesn't have a direct way to probe for `const fn` yet. - if ac.probe_rustc_version(1, 31) { - autocfg::emit("has_const_fn"); - } - - autocfg::rerun_path("build.rs"); -} diff --git a/src/lib.rs b/src/lib.rs index 1b8f4ce..5f69183 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,19 +93,11 @@ pub type Complex32 = Complex; pub type Complex64 = Complex; impl Complex { - #[cfg(has_const_fn)] /// Create a new Complex #[inline] pub const fn new(re: T, im: T) -> Self { Complex { re: re, im: im } } - - #[cfg(not(has_const_fn))] - /// Create a new Complex - #[inline] - pub fn new(re: T, im: T) -> Self { - Complex { re: re, im: im } - } } impl Complex { @@ -2647,7 +2639,6 @@ mod test { assert!(c.is_one()); } - #[cfg(has_const_fn)] #[test] fn test_const() { const R: f64 = 12.3;