Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit e07e255

Browse files
committed
Remove support for saturating shifts
The implementation in stdlib has been removed as part of stabilizing rust-lang/rust#87920. Support for saturating shifts will be added back once rust-lang/libs-team#230 is fixed.
1 parent e7a5b19 commit e07e255

File tree

7 files changed

+8
-49
lines changed

7 files changed

+8
-49
lines changed

.github/workflows/rust.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Run tests
2222
run: cargo test --verbose
2323
- run: rustup install nightly
24-
- run: cargo +nightly test --verbose --features saturating_int_impl
24+
- run: cargo +nightly test --verbose
2525

2626
build-windows:
2727

@@ -34,4 +34,4 @@ jobs:
3434
- name: Run tests
3535
run: cargo test --verbose
3636
- run: rustup install nightly
37-
- run: cargo +nightly test --verbose --features saturating_int_impl
37+
- run: cargo +nightly test --verbose

.vscode/settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"rust-analyzer.cargo.features": [
3-
"saturating_int_impl"
43
]
54
}

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ proc-macro = true
88

99
[features]
1010
default = []
11-
saturating_int_impl = [] # Requires nightly and the lang-feature of the same name
1211

1312
[dependencies]
1413
anyhow = "1.0.75"

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ wrapping! { 1_i32 + 2_i32 - 3_i32 };
1717
* Sub `-`
1818
* Mul `*`
1919
* Div `/`
20-
* Shl `<<` (except `saturating`, which is only supported with the feature
21-
`saturating_int_impl`, and requires nightly)
22-
* Shr `>>` (except `saturating`, which is only supported with the feature
23-
`saturating_int_impl`, and requires nightly)
20+
* Shl `<<` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230)
21+
* Shr `>>` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230)
2422
## Known issues
2523
* For most operations, constraining the numeric literals are required (e.g.
2624
`2_i32` instead of `2`), due to

src/lib.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
//! * Sub `-`
2020
//! * Mul `*`
2121
//! * Div `/`
22-
//! * Shl `<<` (except `saturating`, which is only supported with the feature
23-
//! `saturating_int_impl`, and requires nightly)
24-
//! * Shr `>>` (except `saturating`, which is only supported with the feature
25-
//! `saturating_int_impl`, and requires nightly)
22+
//! * Shl `<<` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230)
23+
//! * Shr `>>` (except `saturating`, due to https://github.com/rust-lang/libs-team/issues/230)
2624
//!
2725
//! ## Known issues
2826
//! * For most operations, constraining the numeric literals are required (e.g.
@@ -175,26 +173,10 @@ fn saturating_impl(item: TokenStream) -> anyhow::Result<TokenStream> {
175173
syn::BinOp::Div(_) => quote! { (#new_left).saturating_div(#new_right) },
176174
syn::BinOp::Rem(_) => quote! { (#new_left).saturating_rem(#new_right) },
177175
syn::BinOp::Shl(_) => {
178-
#[cfg(feature = "saturating_int_impl")]
179-
{
180-
quote! { (::core::num::Saturating(#new_left) #op (#new_right)).0 }
181-
}
182-
183-
#[cfg(not(feature = "saturating_int_impl"))]
184-
{
185-
bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)")
186-
}
176+
bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)")
187177
}
188178
syn::BinOp::Shr(_) => {
189-
#[cfg(feature = "saturating_int_impl")]
190-
{
191-
quote! { (::core::num::Saturating(#new_left) #op (#new_right)).0 }
192-
}
193-
194-
#[cfg(not(feature = "saturating_int_impl"))]
195-
{
196-
bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)")
197-
}
179+
bail!("Saturating bit shifts are not supported (https://github.com/rust-lang/libs-team/issues/230)")
198180
}
199181
syn::BinOp::And(_)
200182
| syn::BinOp::Or(_)

src/tests.rs

-9
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,7 @@ fn test_bitshift() {
122122
});
123123
}
124124

125-
#[cfg_attr(feature = "saturating_int_impl", ignore)]
126125
#[test]
127126
fn test_bitshift_no_saturating() {
128127
saturating_impl(quote! { 1 << 2 >> 3 }).unwrap_err();
129128
}
130-
131-
#[test]
132-
#[cfg_attr(not(feature = "saturating_int_impl"), ignore)]
133-
fn test_bitshift_saturating() {
134-
assert_expansion!(saturating_impl! { 1 << 2 >> 3 }.unwrap(), {
135-
(::core::num::Saturating((::core::num::Saturating(1) << (2)).0) >> (3)).0
136-
});
137-
}

tests/test.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![cfg_attr(feature="saturating_int_impl", feature(saturating_int_impl))]
32
#![allow(clippy::precedence)]
43

54
use arithmetic_mode::{checked, panicking, saturating, wrapping};
@@ -74,15 +73,6 @@ fn test_checked_operator_precedence() {
7473
assert_eq!(Some(11), checked! { 1_u8 + 2_u8 * 3_u8 + 4_u8 });
7574
}
7675

77-
#[cfg(feature="saturating_int_impl")]
78-
#[test]
79-
fn test_saturating_shift() {
80-
// Looks like the implementation of shift is just wrapping_shl / shr
81-
// https://doc.rust-lang.org/src/core/num/saturating.rs.html#146
82-
assert_eq!(2, saturating! { 1_u8 << 9_usize });
83-
assert_eq!(127, saturating! { 255_u8 >> 9_usize });
84-
}
85-
8676
macro_rules! test_unchanging {
8777
($ident:ident, $expr:expr) => {
8878
::paste::paste! {

0 commit comments

Comments
 (0)