diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-07-05 08:26:32 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-07-05 10:55:35 +0200 |
| commit | 226b0fbe11812c71c8002b10a40063571cf52b3f (patch) | |
| tree | 20deaf0bfa759fbeeb59a7ea782790d84af63b80 /library/core/src/slice/mod.rs | |
| parent | 733b47ea4b1b86216f14ef56e49440c33933f230 (diff) | |
| download | rust-226b0fbe11812c71c8002b10a40063571cf52b3f.tar.gz rust-226b0fbe11812c71c8002b10a40063571cf52b3f.zip | |
use `is_multiple_of` instead of manual modulo
Diffstat (limited to 'library/core/src/slice/mod.rs')
| -rw-r--r-- | library/core/src/slice/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 3a3f44c6b85..dc09ba8d788 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1316,7 +1316,7 @@ impl<T> [T] { assert_unsafe_precondition!( check_language_ub, "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks", - (n: usize = N, len: usize = self.len()) => n != 0 && len % n == 0, + (n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n), ); // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length let new_len = unsafe { exact_div(self.len(), N) }; @@ -1512,7 +1512,7 @@ impl<T> [T] { assert_unsafe_precondition!( check_language_ub, "slice::as_chunks_unchecked requires `N != 0` and the slice to split exactly into `N`-element chunks", - (n: usize = N, len: usize = self.len()) => n != 0 && len % n == 0 + (n: usize = N, len: usize = self.len()) => n != 0 && len.is_multiple_of(n) ); // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length let new_len = unsafe { exact_div(self.len(), N) }; @@ -4866,7 +4866,7 @@ impl<T> [T] { let byte_offset = elem_start.wrapping_sub(self_start); - if byte_offset % size_of::<T>() != 0 { + if !byte_offset.is_multiple_of(size_of::<T>()) { return None; } @@ -4920,7 +4920,7 @@ impl<T> [T] { let byte_start = subslice_start.wrapping_sub(self_start); - if byte_start % size_of::<T>() != 0 { + if !byte_start.is_multiple_of(size_of::<T>()) { return None; } |
