diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2a4a9e7..b562a0e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: - name: Run tests run: cargo test --verbose - run: rustup install nightly - - run: cargo +nightly test --verbose --features saturating_int_impl + - run: cargo +nightly test --verbose build-windows: @@ -34,4 +34,4 @@ jobs: - name: Run tests run: cargo test --verbose - run: rustup install nightly - - run: cargo +nightly test --verbose --features saturating_int_impl + - run: cargo +nightly test --verbose diff --git a/.vscode/settings.json b/.vscode/settings.json index 88109bc..37ed364 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { "rust-analyzer.cargo.features": [ - "saturating_int_impl" ] } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index bfe62f9..ebdecb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ proc-macro = true [features] default = [] -saturating_int_impl = [] # Requires nightly and the lang-feature of the same name [dependencies] anyhow = "1.0.75" diff --git a/README.md b/README.md index 1894c1f..3106fa9 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,8 @@ wrapping! { 1_i32 + 2_i32 - 3_i32 }; * Sub `-` * Mul `*` * Div `/` -* Shl `<<` (except `saturating`, which is only supported with the feature - `saturating_int_impl`, and requires nightly) -* Shr `>>` (except `saturating`, which is only supported with the feature - `saturating_int_impl`, and requires nightly) +* Shl `<<` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230) +* Shr `>>` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230) ## Known issues * For most operations, constraining the numeric literals are required (e.g. `2_i32` instead of `2`), due to diff --git a/src/lib.rs b/src/lib.rs index b3ad51b..46688bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,10 +19,8 @@ //! * Sub `-` //! * Mul `*` //! * Div `/` -//! * Shl `<<` (except `saturating`, which is only supported with the feature -//! `saturating_int_impl`, and requires nightly) -//! * Shr `>>` (except `saturating`, which is only supported with the feature -//! `saturating_int_impl`, and requires nightly) +//! * Shl `<<` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230) +//! * Shr `>>` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230) //! //! ## Known issues //! * For most operations, constraining the numeric literals are required (e.g. @@ -175,26 +173,10 @@ fn saturating_impl(item: TokenStream) -> anyhow::Result { syn::BinOp::Div(_) => quote! { (#new_left).saturating_div(#new_right) }, syn::BinOp::Rem(_) => quote! { (#new_left).saturating_rem(#new_right) }, syn::BinOp::Shl(_) => { - #[cfg(feature = "saturating_int_impl")] - { - quote! { (::core::num::Saturating(#new_left) #op (#new_right)).0 } - } - - #[cfg(not(feature = "saturating_int_impl"))] - { - bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)") - } + bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)") } syn::BinOp::Shr(_) => { - #[cfg(feature = "saturating_int_impl")] - { - quote! { (::core::num::Saturating(#new_left) #op (#new_right)).0 } - } - - #[cfg(not(feature = "saturating_int_impl"))] - { - bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)") - } + bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)") } syn::BinOp::And(_) | syn::BinOp::Or(_) diff --git a/src/tests.rs b/src/tests.rs index a087cad..392d2b4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -122,16 +122,7 @@ fn test_bitshift() { }); } -#[cfg_attr(feature = "saturating_int_impl", ignore)] #[test] fn test_bitshift_no_saturating() { saturating_impl(quote! { 1 << 2 >> 3 }).unwrap_err(); } - -#[test] -#[cfg_attr(not(feature = "saturating_int_impl"), ignore)] -fn test_bitshift_saturating() { - assert_expansion!(saturating_impl! { 1 << 2 >> 3 }.unwrap(), { - (::core::num::Saturating((::core::num::Saturating(1) << (2)).0) >> (3)).0 - }); -} diff --git a/tests/test.rs b/tests/test.rs index cecadee..8680668 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,5 +1,4 @@ #![no_std] -#![cfg_attr(feature="saturating_int_impl", feature(saturating_int_impl))] #![allow(clippy::precedence)] use arithmetic_mode::{checked, panicking, saturating, wrapping}; @@ -74,15 +73,6 @@ fn test_checked_operator_precedence() { assert_eq!(Some(11), checked! { 1_u8 + 2_u8 * 3_u8 + 4_u8 }); } -#[cfg(feature="saturating_int_impl")] -#[test] -fn test_saturating_shift() { - // Looks like the implementation of shift is just wrapping_shl / shr - // https://doc.rust-lang.org/src/core/num/saturating.rs.html#146 - assert_eq!(2, saturating! { 1_u8 << 9_usize }); - assert_eq!(127, saturating! { 255_u8 >> 9_usize }); -} - macro_rules! test_unchanging { ($ident:ident, $expr:expr) => { ::paste::paste! {