Skip to content

Commit af2315f

Browse files
committed
use is_multiple_of instead of manual modulo
1 parent 5c88806 commit af2315f

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

core/src/slice/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ impl<T> [T] {
13161316
assert_unsafe_precondition!(
13171317
check_language_ub,
13181318
"slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks",
1319-
(n: usize = N, len: usize = self.len()) => n != 0 && len % n == 0,
1319+
(n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n),
13201320
);
13211321
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
13221322
let new_len = unsafe { exact_div(self.len(), N) };
@@ -1512,7 +1512,7 @@ impl<T> [T] {
15121512
assert_unsafe_precondition!(
15131513
check_language_ub,
15141514
"slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks",
1515-
(n: usize = N, len: usize = self.len()) => n != 0 && len % n == 0
1515+
(n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n)
15161516
);
15171517
// SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length
15181518
let new_len = unsafe { exact_div(self.len(), N) };
@@ -4866,7 +4866,7 @@ impl<T> [T] {
48664866

48674867
let byte_offset = elem_start.wrapping_sub(self_start);
48684868

4869-
if byte_offset % size_of::<T>() != 0 {
4869+
if !byte_offset.is_multiple_of(size_of::<T>()) {
48704870
return None;
48714871
}
48724872

@@ -4920,7 +4920,7 @@ impl<T> [T] {
49204920

49214921
let byte_start = subslice_start.wrapping_sub(self_start);
49224922

4923-
if byte_start % size_of::<T>() != 0 {
4923+
if !byte_start.is_multiple_of(size_of::<T>()) {
49244924
return None;
49254925
}
49264926

core/src/slice/sort/shared/smallsort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ unsafe fn bidirectional_merge<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(
823823
let right_end = right_rev.wrapping_add(1);
824824

825825
// Odd length, so one element is left unconsumed in the input.
826-
if len % 2 != 0 {
826+
if !len.is_multiple_of(2) {
827827
let left_nonempty = left < left_end;
828828
let last_src = if left_nonempty { left } else { right };
829829
ptr::copy_nonoverlapping(last_src, dst, 1);

core/src/str/count.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn do_count_chars(s: &str) -> usize {
5252
// Check the properties of `CHUNK_SIZE` and `UNROLL_INNER` that are required
5353
// for correctness.
5454
const _: () = assert!(CHUNK_SIZE < 256);
55-
const _: () = assert!(CHUNK_SIZE % UNROLL_INNER == 0);
55+
const _: () = assert!(CHUNK_SIZE.is_multiple_of(UNROLL_INNER));
5656

5757
// SAFETY: transmuting `[u8]` to `[usize]` is safe except for size
5858
// differences which are handled by `align_to`.

core/src/str/validations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub(super) const fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
219219
// Ascii case, try to skip forward quickly.
220220
// When the pointer is aligned, read 2 words of data per iteration
221221
// until we find a word containing a non-ascii byte.
222-
if align != usize::MAX && align.wrapping_sub(index) % USIZE_BYTES == 0 {
222+
if align != usize::MAX && align.wrapping_sub(index).is_multiple_of(USIZE_BYTES) {
223223
let ptr = v.as_ptr();
224224
while index < blocks_end {
225225
// SAFETY: since `align - index` and `ascii_block_size` are

0 commit comments

Comments
 (0)