diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad2ccbd..28aa341 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: rust: [ - 1.91.0, # MSRV + 1.93.0, # MSRV stable, beta, nightly, @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@1.91.0 + - uses: dtolnay/rust-toolchain@1.93.0 with: components: rustfmt - run: cargo fmt --all --check diff --git a/Cargo.toml b/Cargo.toml index a8db70c..52d7d61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "num-primitive" -version = "0.3.4" +version = "0.3.5" description = "Traits for primitive numeric types" repository = "https://github.com/rust-num/num-primitive" license = "MIT OR Apache-2.0" keywords = ["generic", "mathematics", "numerics", "primitive"] categories = ["algorithms", "science", "no-std"] edition = "2024" -rust-version = "1.91" +rust-version = "1.93" [package.metadata.release] allow-branch = ["main"] diff --git a/README.md b/README.md index 6bdd715..873f914 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-primitive.svg)](https://crates.io/crates/num-primitive) [![documentation](https://docs.rs/num-primitive/badge.svg)](https://docs.rs/num-primitive) -[![minimum rustc 1.91](https://img.shields.io/badge/rustc-1.91+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![minimum rustc 1.93](https://img.shields.io/badge/rustc-1.93+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) [![build status](https://github.com/rust-num/num-primitive/workflows/CI/badge.svg)](https://github.com/rust-num/num-primitive/actions) Traits for primitive numeric types in Rust. @@ -61,7 +61,7 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-primitive` crate is currently tested for Rust 1.91 and greater. This +The `num-primitive` crate is currently tested for Rust 1.93 and greater. This minimum-supported Rust version (MSRV) may be increased at any time to add support for newly-stabilized functionality from the standard library. Changes will be documented prominently in the release notes. diff --git a/RELEASES.md b/RELEASES.md index 579f9a5..380ebcc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,9 @@ +# Release 0.3.5 (2026-01-22) + +- Updated to MSRV 1.93. +- Added `PrimitiveInteger::unchecked_{shl,shr}`. +- Added `PrimitiveSigned::unchecked_neg`. + # Release 0.3.4 (2025-12-20) - Added `PrimitiveInteger::from_str_radix`. diff --git a/src/integer.rs b/src/integer.rs index cec4794..4ce0f0e 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -492,6 +492,24 @@ pub trait PrimitiveInteger: /// Self::MIN`, i.e. when [`checked_mul`][Self::checked_mul] would return `None`. unsafe fn unchecked_mul(self, rhs: Self) -> Self; + /// Unchecked shift left. Computes `self << rhs`, assuming that + /// `rhs` is less than the number of bits in `self`. + /// + /// # Safety + /// + /// This results in undefined behavior if `rhs` is larger than or equal to the number of bits + /// in `self`, i.e. when [`checked_shl`][Self::checked_shl] would return `None`. + unsafe fn unchecked_shl(self, rhs: u32) -> Self; + + /// Unchecked shift right. Computes `self >> rhs`, assuming that + /// `rhs` is less than the number of bits in `self`. + /// + /// # Safety + /// + /// This results in undefined behavior if `rhs` is larger than or equal to the number of bits + /// in `self`, i.e. when [`checked_shr`][Self::checked_shr] would return `None`. + unsafe fn unchecked_shr(self, rhs: u32) -> Self; + /// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow cannot occur. /// /// # Safety @@ -668,6 +686,8 @@ macro_rules! impl_integer { forward! { unsafe fn unchecked_add(self, rhs: Self) -> Self; unsafe fn unchecked_mul(self, rhs: Self) -> Self; + unsafe fn unchecked_shl(self, rhs: u32) -> Self; + unsafe fn unchecked_shr(self, rhs: u32) -> Self; unsafe fn unchecked_sub(self, rhs: Self) -> Self; } } diff --git a/src/signed.rs b/src/signed.rs index cc6aa42..01af8ca 100644 --- a/src/signed.rs +++ b/src/signed.rs @@ -146,6 +146,14 @@ pub trait PrimitiveSigned: /// Wrapping (modular) subtraction with an unsigned integer. Computes `self - rhs`, wrapping /// around at the boundary of the type. fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self; + + /// Unchecked negation. Computes `-self`, assuming overflow cannot occur. + /// + /// # Safety + /// + /// This results in undefined behavior when `self == Self::MIN`, i.e. when + /// [`checked_neg`][PrimitiveInteger::checked_neg] would return `None`. + unsafe fn unchecked_neg(self) -> Self; } /// Trait for references to primitive signed integer types ([`PrimitiveSigned`]). @@ -185,6 +193,9 @@ macro_rules! impl_signed { fn wrapping_add_unsigned(self, rhs: Self::Unsigned) -> Self; fn wrapping_sub_unsigned(self, rhs: Self::Unsigned) -> Self; } + forward! { + unsafe fn unchecked_neg(self) -> Self; + } } impl PrimitiveSignedRef<$Signed> for &$Signed {}