Skip to content

Commit

Permalink
hybrid-array: use assert_ne! in slice_as_chunks(_mut) (#1016)
Browse files Browse the repository at this point in the history
Provides more effective debugging in the event the wrong size is used
  • Loading branch information
tarcieri committed Dec 31, 2023
1 parent a15a4aa commit 35e61ad
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ impl<T, const N: usize> FromFn<T> for [T; N] {
/// Panics if `N` is 0.
#[allow(clippy::arithmetic_side_effects)]
pub fn slice_as_chunks<T, N: ArraySize>(buf: &[T]) -> (&[Array<T, N>], &[T]) {
assert!(N::USIZE != 0, "chunk size must be non-zero");
assert_ne!(N::USIZE, 0, "chunk size must be non-zero");
// Arithmetic safety: we have checked that `N::USIZE` is not zero, thus
// division always returns correct result. `tail_pos` can not be bigger than `buf.len()`,
// thus overflow on multiplication and underflow on substraction are impossible.
Expand All @@ -763,7 +763,7 @@ pub fn slice_as_chunks<T, N: ArraySize>(buf: &[T]) -> (&[Array<T, N>], &[T]) {
/// Panics if `N` is 0.
#[allow(clippy::arithmetic_side_effects)]
pub fn slice_as_chunks_mut<T, N: ArraySize>(buf: &mut [T]) -> (&mut [Array<T, N>], &mut [T]) {
assert!(N::USIZE != 0, "chunk size must be non-zero");
assert_ne!(N::USIZE, 0, "chunk size must be non-zero");
// Arithmetic safety: we have checked that `N::USIZE` is not zero, thus
// division always returns correct result. `tail_pos` can not be bigger than `buf.len()`,
// thus overflow on multiplication and underflow on substraction are impossible.
Expand Down

0 comments on commit 35e61ad

Please sign in to comment.