From b1f209bcd75cdead46bcf1ad409d65cac6f14a0a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 15:45:32 -0700 Subject: [PATCH 1/8] Upgrade to 2018 edition --- Cargo.toml | 1 + benches/average.rs | 2 -- benches/gcd.rs | 2 -- benches/roots.rs | 18 ++++++++---------- build.rs | 2 -- src/average.rs | 2 +- src/lib.rs | 18 +++++++++--------- src/roots.rs | 7 +++---- tests/average.rs | 19 ++++++++----------- tests/roots.rs | 13 +++++-------- 10 files changed, 35 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f5aac54..9a217d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ version = "0.1.45" readme = "README.md" build = "build.rs" exclude = ["/bors.toml", "/ci/*", "/.github/*"] +edition = "2018" [package.metadata.docs.rs] features = ["std"] diff --git a/benches/average.rs b/benches/average.rs index 649078c..fbf899f 100644 --- a/benches/average.rs +++ b/benches/average.rs @@ -2,8 +2,6 @@ #![feature(test)] -extern crate num_integer; -extern crate num_traits; extern crate test; use num_integer::Integer; diff --git a/benches/gcd.rs b/benches/gcd.rs index 082d5ee..11b407b 100644 --- a/benches/gcd.rs +++ b/benches/gcd.rs @@ -2,8 +2,6 @@ #![feature(test)] -extern crate num_integer; -extern crate num_traits; extern crate test; use num_integer::Integer; diff --git a/benches/roots.rs b/benches/roots.rs index 7f67278..b02ec86 100644 --- a/benches/roots.rs +++ b/benches/roots.rs @@ -2,8 +2,6 @@ #![feature(test)] -extern crate num_integer; -extern crate num_traits; extern crate test; use num_integer::Integer; @@ -125,42 +123,42 @@ macro_rules! bench_roots { #[bench] fn sqrt_rand(b: &mut Bencher) { - ::bench_rand_pos(b, $T::sqrt, 2); + crate::bench_rand_pos(b, $T::sqrt, 2); } #[bench] fn sqrt_small(b: &mut Bencher) { - ::bench_small_pos(b, $T::sqrt, 2); + crate::bench_small_pos(b, $T::sqrt, 2); } #[bench] fn cbrt_rand(b: &mut Bencher) { - ::bench_rand(b, $T::cbrt, 3); + crate::bench_rand(b, $T::cbrt, 3); } #[bench] fn cbrt_small(b: &mut Bencher) { - ::bench_small(b, $T::cbrt, 3); + crate::bench_small(b, $T::cbrt, 3); } #[bench] fn fourth_root_rand(b: &mut Bencher) { - ::bench_rand_pos(b, |x: &$T| x.nth_root(4), 4); + crate::bench_rand_pos(b, |x: &$T| x.nth_root(4), 4); } #[bench] fn fourth_root_small(b: &mut Bencher) { - ::bench_small_pos(b, |x: &$T| x.nth_root(4), 4); + crate::bench_small_pos(b, |x: &$T| x.nth_root(4), 4); } #[bench] fn fifth_root_rand(b: &mut Bencher) { - ::bench_rand(b, |x: &$T| x.nth_root(5), 5); + crate::bench_rand(b, |x: &$T| x.nth_root(5), 5); } #[bench] fn fifth_root_small(b: &mut Bencher) { - ::bench_small(b, |x: &$T| x.nth_root(5), 5); + crate::bench_small(b, |x: &$T| x.nth_root(5), 5); } } )*} diff --git a/build.rs b/build.rs index 37c9857..79ba710 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,3 @@ -extern crate autocfg; - use std::env; fn main() { diff --git a/src/average.rs b/src/average.rs index 29cd11e..eb854d8 100644 --- a/src/average.rs +++ b/src/average.rs @@ -1,5 +1,5 @@ +use crate::Integer; use core::ops::{BitAnd, BitOr, BitXor, Shr}; -use Integer; /// Provides methods to compute the average of two integers, without overflows. pub trait Average: Integer { diff --git a/src/lib.rs b/src/lib.rs index 5005801..3c4734f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,15 +24,15 @@ extern crate num_traits as traits; use core::mem; use core::ops::Add; -use traits::{Num, Signed, Zero}; +use crate::traits::{Num, Signed, Zero}; mod roots; -pub use roots::Roots; -pub use roots::{cbrt, nth_root, sqrt}; +pub use crate::roots::Roots; +pub use crate::roots::{cbrt, nth_root, sqrt}; mod average; -pub use average::Average; -pub use average::{average_ceil, average_floor}; +pub use crate::average::Average; +pub use crate::average::{average_ceil, average_floor}; pub trait Integer: Sized + Num + PartialOrd + Ord + Eq { /// Floored integer division. @@ -590,8 +590,8 @@ macro_rules! impl_integer_for_isize { #[cfg(test)] mod $test_mod { + use crate::Integer; use core::mem; - use Integer; /// Checks that the division rule holds for: /// @@ -758,9 +758,9 @@ macro_rules! impl_integer_for_isize { #[test] fn test_extended_gcd_lcm() { + use crate::traits::NumAssign; + use crate::ExtendedGcd; use core::fmt::Debug; - use traits::NumAssign; - use ExtendedGcd; fn check(a: A, b: A) { let ExtendedGcd { gcd, x, y, .. } = a.extended_gcd(&b); @@ -945,8 +945,8 @@ macro_rules! impl_integer_for_usize { #[cfg(test)] mod $test_mod { + use crate::Integer; use core::mem; - use Integer; #[test] fn test_div_mod_floor() { diff --git a/src/roots.rs b/src/roots.rs index a9eec1a..87c50a1 100644 --- a/src/roots.rs +++ b/src/roots.rs @@ -1,8 +1,7 @@ -use core; +use crate::traits::checked_pow; +use crate::traits::PrimInt; +use crate::Integer; use core::mem; -use traits::checked_pow; -use traits::PrimInt; -use Integer; /// Provides methods to compute an integer's square root, cube root, /// and arbitrary `n`th root. diff --git a/tests/average.rs b/tests/average.rs index 9fd8cf1..c8f14ca 100644 --- a/tests/average.rs +++ b/tests/average.rs @@ -1,6 +1,3 @@ -extern crate num_integer; -extern crate num_traits; - macro_rules! test_average { ($I:ident, $U:ident) => { mod $I { @@ -12,7 +9,7 @@ macro_rules! test_average { assert_eq!((14 as $I).average_ceil(&16), 15 as $I); assert_eq!((14 as $I).average_ceil(&17), 16 as $I); - let max = $crate::std::$I::MAX; + let max = std::$I::MAX; assert_eq!((max - 3).average_ceil(&(max - 1)), max - 2); assert_eq!((max - 3).average_ceil(&(max - 2)), max - 2); } @@ -22,8 +19,8 @@ macro_rules! test_average { assert_eq!((14 as $I).average_ceil(&-4), 5 as $I); assert_eq!((14 as $I).average_ceil(&-5), 5 as $I); - let min = $crate::std::$I::MIN; - let max = $crate::std::$I::MAX; + let min = std::$I::MIN; + let max = std::$I::MAX; assert_eq!(min.average_ceil(&max), 0 as $I); } } @@ -36,7 +33,7 @@ macro_rules! test_average { assert_eq!((14 as $I).average_floor(&16), 15 as $I); assert_eq!((14 as $I).average_floor(&17), 15 as $I); - let max = $crate::std::$I::MAX; + let max = std::$I::MAX; assert_eq!((max - 3).average_floor(&(max - 1)), max - 2); assert_eq!((max - 3).average_floor(&(max - 2)), max - 3); } @@ -46,8 +43,8 @@ macro_rules! test_average { assert_eq!((14 as $I).average_floor(&-4), 5 as $I); assert_eq!((14 as $I).average_floor(&-5), 4 as $I); - let min = $crate::std::$I::MIN; - let max = $crate::std::$I::MAX; + let min = std::$I::MIN; + let max = std::$I::MAX; assert_eq!(min.average_floor(&max), -1 as $I); } } @@ -65,7 +62,7 @@ macro_rules! test_average { #[test] fn overflow() { - let max = $crate::std::$U::MAX; + let max = std::$U::MAX; assert_eq!((max - 3).average_ceil(&(max - 1)), max - 2); assert_eq!((max - 3).average_ceil(&(max - 2)), max - 2); } @@ -82,7 +79,7 @@ macro_rules! test_average { #[test] fn overflow() { - let max = $crate::std::$U::MAX; + let max = std::$U::MAX; assert_eq!((max - 3).average_floor(&(max - 1)), max - 2); assert_eq!((max - 3).average_floor(&(max - 2)), max - 3); } diff --git a/tests/roots.rs b/tests/roots.rs index f85f9e0..be6c01c 100644 --- a/tests/roots.rs +++ b/tests/roots.rs @@ -1,6 +1,3 @@ -extern crate num_integer; -extern crate num_traits; - use num_integer::Roots; use num_traits::checked_pow; use num_traits::{AsPrimitive, PrimInt, Signed}; @@ -161,10 +158,10 @@ where macro_rules! test_roots { ($I:ident, $U:ident) => { mod $I { - use check; - use neg; + use crate::check; + use crate::neg; + use crate::pos; use num_integer::Roots; - use pos; use std::mem; #[test] @@ -223,9 +220,9 @@ macro_rules! test_roots { } mod $U { - use check; + use crate::check; + use crate::pos; use num_integer::Roots; - use pos; use std::mem; #[test] From 43c534de3a43d66537d13d0db616e48008b0955b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 15:47:13 -0700 Subject: [PATCH 2/8] Update MSRV to 1.31 --- .github/workflows/ci.yaml | 2 +- .github/workflows/master.yaml | 2 +- .github/workflows/pr.yaml | 2 +- Cargo.toml | 1 + README.md | 4 ++-- bors.toml | 4 ---- ci/rustup.sh | 2 +- ci/test_full.sh | 2 +- src/lib.rs | 2 +- 9 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 82c0ff0..f33c936 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.8.0, 1.15.0, 1.20.0, 1.26.0, 1.31.0, stable, beta, nightly] + rust: [1.31.0, stable, beta, nightly] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index 8c4349e..98e8f8e 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.8.0, stable] + rust: [1.31.0, stable] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 36d97a3..d221a73 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.8.0, stable] + rust: [1.31.0, stable] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master diff --git a/Cargo.toml b/Cargo.toml index 9a217d7..1dcc4f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ readme = "README.md" build = "build.rs" exclude = ["/bors.toml", "/ci/*", "/.github/*"] edition = "2018" +rust-version = "1.31" [package.metadata.docs.rs] features = ["std"] diff --git a/README.md b/README.md index 5f638cd..5fca724 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-integer.svg)](https://crates.io/crates/num-integer) [![documentation](https://docs.rs/num-integer/badge.svg)](https://docs.rs/num-integer) -[![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![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) [![build status](https://github.com/rust-num/num-integer/workflows/master/badge.svg)](https://github.com/rust-num/num-integer/actions) `Integer` trait and functions for Rust. @@ -46,7 +46,7 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-integer` crate is tested for rustc 1.8 and greater. +The `num-integer` crate is tested for rustc 1.31 and greater. ## License diff --git a/bors.toml b/bors.toml index e0c5618..4c20337 100644 --- a/bors.toml +++ b/bors.toml @@ -1,8 +1,4 @@ status = [ - "Test (1.8.0)", - "Test (1.15.0)", - "Test (1.20.0)", - "Test (1.26.0)", "Test (1.31.0)", "Test (stable)", "Test (beta)", diff --git a/ci/rustup.sh b/ci/rustup.sh index 9d0fc30..fed3e45 100755 --- a/ci/rustup.sh +++ b/ci/rustup.sh @@ -5,6 +5,6 @@ set -ex ci=$(dirname $0) -for version in 1.8.0 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do +for version in 1.31.0 stable beta nightly; do rustup run "$version" "$ci/test_full.sh" done diff --git a/ci/test_full.sh b/ci/test_full.sh index ccbcc94..a48c1e0 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -3,7 +3,7 @@ set -e CRATE=num-integer -MSRV=1.8 +MSRV=1.31 get_rust_version() { local array=($(rustc --version)); diff --git a/src/lib.rs b/src/lib.rs index 3c4734f..bd2e6ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ //! //! ## Compatibility //! -//! The `num-integer` crate is tested for rustc 1.8 and greater. +//! The `num-integer` crate is tested for rustc 1.31 and greater. #![doc(html_root_url = "https://docs.rs/num-integer/0.1")] #![no_std] From 4d86cd18b73a6afe403b623f336dbb5ccc34707e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 15:50:52 -0700 Subject: [PATCH 3/8] Assume i128 support --- .github/workflows/ci.yaml | 2 +- Cargo.toml | 7 +++---- README.md | 4 ---- build.rs | 11 ----------- ci/test_full.sh | 1 - src/lib.rs | 6 ++---- src/roots.rs | 2 -- tests/average.rs | 1 - tests/roots.rs | 1 - 9 files changed, 6 insertions(+), 29 deletions(-) delete mode 100644 build.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f33c936..02bbf52 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: target: thumbv6m-none-eabi - - run: cargo build --target thumbv6m-none-eabi --no-default-features --features i128 + - run: cargo build --target thumbv6m-none-eabi --no-default-features fmt: name: Format diff --git a/Cargo.toml b/Cargo.toml index 1dcc4f4..603ad65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ repository = "https://github.com/rust-num/num-integer" name = "num-integer" version = "0.1.45" readme = "README.md" -build = "build.rs" exclude = ["/bors.toml", "/ci/*", "/.github/*"] edition = "2018" rust-version = "1.31" @@ -21,11 +20,11 @@ features = ["std"] [dependencies.num-traits] version = "0.2.11" default-features = false +features = ["i128"] [features] default = ["std"] -i128 = ["num-traits/i128"] std = ["num-traits/std"] -[build-dependencies] -autocfg = "1" +# vestigial features, now always in effect +i128 = [] diff --git a/README.md b/README.md index 5fca724..bee5e4c 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,6 @@ default-features = false There is no functional difference with and without `std` at this time, but there may be in the future. -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 deleted file mode 100644 index 79ba710..0000000 --- a/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::env; - -fn main() { - // If the "i128" feature is explicity requested, don't bother probing for it. - // It will still cause a build error if that was set improperly. - if env::var_os("CARGO_FEATURE_I128").is_some() || autocfg::new().probe_type("i128") { - autocfg::emit("has_i128"); - } - - autocfg::rerun_path("build.rs"); -} diff --git a/ci/test_full.sh b/ci/test_full.sh index a48c1e0..c03cec7 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -28,7 +28,6 @@ if ! check_version $MSRV ; then fi FEATURES=() -check_version 1.26 && FEATURES+=(i128) echo "Testing supported features: ${FEATURES[*]}" set -x diff --git a/src/lib.rs b/src/lib.rs index bd2e6ab..3bc5f31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -826,9 +826,8 @@ impl_integer_for_isize!(i8, test_integer_i8); impl_integer_for_isize!(i16, test_integer_i16); impl_integer_for_isize!(i32, test_integer_i32); impl_integer_for_isize!(i64, test_integer_i64); -impl_integer_for_isize!(isize, test_integer_isize); -#[cfg(has_i128)] impl_integer_for_isize!(i128, test_integer_i128); +impl_integer_for_isize!(isize, test_integer_isize); macro_rules! impl_integer_for_usize { ($T:ty, $test_mod:ident) => { @@ -1052,9 +1051,8 @@ impl_integer_for_usize!(u8, test_integer_u8); impl_integer_for_usize!(u16, test_integer_u16); impl_integer_for_usize!(u32, test_integer_u32); impl_integer_for_usize!(u64, test_integer_u64); -impl_integer_for_usize!(usize, test_integer_usize); -#[cfg(has_i128)] impl_integer_for_usize!(u128, test_integer_u128); +impl_integer_for_usize!(usize, test_integer_usize); /// An iterator over binomial coefficients. pub struct IterBinomial { diff --git a/src/roots.rs b/src/roots.rs index 87c50a1..843b528 100644 --- a/src/roots.rs +++ b/src/roots.rs @@ -165,7 +165,6 @@ signed_roots!(i8, u8); signed_roots!(i16, u16); signed_roots!(i32, u32); signed_roots!(i64, u64); -#[cfg(has_i128)] signed_roots!(i128, u128); signed_roots!(isize, usize); @@ -385,6 +384,5 @@ unsigned_roots!(u8); unsigned_roots!(u16); unsigned_roots!(u32); unsigned_roots!(u64); -#[cfg(has_i128)] unsigned_roots!(u128); unsigned_roots!(usize); diff --git a/tests/average.rs b/tests/average.rs index c8f14ca..1c032fd 100644 --- a/tests/average.rs +++ b/tests/average.rs @@ -92,6 +92,5 @@ test_average!(i8, u8); test_average!(i16, u16); test_average!(i32, u32); test_average!(i64, u64); -#[cfg(has_i128)] test_average!(i128, u128); test_average!(isize, usize); diff --git a/tests/roots.rs b/tests/roots.rs index be6c01c..359625c 100644 --- a/tests/roots.rs +++ b/tests/roots.rs @@ -264,6 +264,5 @@ test_roots!(i8, u8); test_roots!(i16, u16); test_roots!(i32, u32); test_roots!(i64, u64); -#[cfg(has_i128)] test_roots!(i128, u128); test_roots!(isize, usize); From 6ba478595bedeceb594b64fcb8ac96dc10f02fe3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 15:53:07 -0700 Subject: [PATCH 4/8] Update CI test versions --- .github/workflows/ci.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 02bbf52..735f256 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [1.31.0, stable, beta, nightly] + rust: [ + 1.31.0, # MSRV + stable, + beta, + nightly, + ] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master From 89a5b397a0cff924d9ef9202de74e65ed23a591e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 15:58:54 -0700 Subject: [PATCH 5/8] Remove useless extern crate --- README.md | 6 ------ src/lib.rs | 10 ++-------- src/roots.rs | 3 +-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index bee5e4c..aefe368 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,6 @@ Add this to your `Cargo.toml`: num-integer = "0.1" ``` -and this to your crate root: - -```rust -extern crate num_integer; -``` - ## Features This crate can be used without the standard library (`#![no_std]`) by disabling diff --git a/src/lib.rs b/src/lib.rs index 3bc5f31..274bf52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,15 +16,11 @@ #![doc(html_root_url = "https://docs.rs/num-integer/0.1")] #![no_std] -#[cfg(feature = "std")] -extern crate std; - -extern crate num_traits as traits; use core::mem; use core::ops::Add; -use crate::traits::{Num, Signed, Zero}; +use num_traits::{Num, Signed, Zero}; mod roots; pub use crate::roots::Roots; @@ -148,8 +144,6 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq { /// # Examples /// /// ~~~ - /// # extern crate num_integer; - /// # extern crate num_traits; /// # fn main() { /// # use num_integer::{ExtendedGcd, Integer}; /// # use num_traits::NumAssign; @@ -758,9 +752,9 @@ macro_rules! impl_integer_for_isize { #[test] fn test_extended_gcd_lcm() { - use crate::traits::NumAssign; use crate::ExtendedGcd; use core::fmt::Debug; + use num_traits::NumAssign; fn check(a: A, b: A) { let ExtendedGcd { gcd, x, y, .. } = a.extended_gcd(&b); diff --git a/src/roots.rs b/src/roots.rs index 843b528..aed3802 100644 --- a/src/roots.rs +++ b/src/roots.rs @@ -1,7 +1,6 @@ -use crate::traits::checked_pow; -use crate::traits::PrimInt; use crate::Integer; use core::mem; +use num_traits::{checked_pow, PrimInt}; /// Provides methods to compute an integer's square root, cube root, /// and arbitrary `n`th root. From 8e9886475da400e5231f1e866f47767f0d1d515a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 16:01:58 -0700 Subject: [PATCH 6/8] Test with inclusive ranges --- src/lib.rs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 274bf52..10dd12e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -673,19 +673,11 @@ macro_rules! impl_integer_for_isize { // gcd(-128, b) = 128 is not representable as positive value // for i8 - for i in -127..127 { - for j in -127..127 { + for i in -127..=127 { + for j in -127..=127 { assert_eq!(euclidean_gcd(i, j), i.gcd(&j)); } } - - // last value - // FIXME: Use inclusive ranges for above loop when implemented - let i = 127; - for j in -127..127 { - assert_eq!(euclidean_gcd(i, j), i.gcd(&j)); - } - assert_eq!(127.gcd(&127), 127); } #[test] @@ -974,19 +966,11 @@ macro_rules! impl_integer_for_usize { n } - for i in 0..255 { - for j in 0..255 { + for i in 0..=255 { + for j in 0..=255 { assert_eq!(euclidean_gcd(i, j), i.gcd(&j)); } } - - // last value - // FIXME: Use inclusive ranges for above loop when implemented - let i = 255; - for j in 0..255 { - assert_eq!(euclidean_gcd(i, j), i.gcd(&j)); - } - assert_eq!(255.gcd(&255), 255); } #[test] From 4cfb1a8bcdfe2f9ef6bbbba0fd8404440e961b47 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 16:04:17 -0700 Subject: [PATCH 7/8] Fix clippy::redundant_field_names --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 10dd12e..1b97f1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1065,7 +1065,7 @@ where IterBinomial { k: T::zero(), a: T::one(), - n: n, + n, } } } From b883758448d522004eba3d0a6657ec7edbf285b9 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 3 May 2022 16:04:45 -0700 Subject: [PATCH 8/8] Fix clippy::collapsible_else_if --- benches/average.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/benches/average.rs b/benches/average.rs index fbf899f..1f81ca6 100644 --- a/benches/average.rs +++ b/benches/average.rs @@ -141,12 +141,10 @@ where assert_eq!(rt - a, b - rt + T::one()); } // if both number have a different sign, + } else if (a + b).is_even() { + assert_eq!(rt, (a + b) / (T::one() + T::one())) } else { - if (a + b).is_even() { - assert_eq!(rt, (a + b) / (T::one() + T::one())) - } else { - assert_eq!(rt, (a + b + T::one()) / (T::one() + T::one())) - } + assert_eq!(rt, (a + b + T::one()) / (T::one() + T::one())) } } bench_unchecked(b, v, f); @@ -168,12 +166,10 @@ where assert_eq!(rt - a + T::one(), b - rt); } // if both number have a different sign, + } else if (a + b).is_even() { + assert_eq!(rt, (a + b) / (T::one() + T::one())) } else { - if (a + b).is_even() { - assert_eq!(rt, (a + b) / (T::one() + T::one())) - } else { - assert_eq!(rt, (a + b - T::one()) / (T::one() + T::one())) - } + assert_eq!(rt, (a + b - T::one()) / (T::one() + T::one())) } } bench_unchecked(b, v, f);