Skip to content

Commit 226b0fb

Browse files
committed
use is_multiple_of instead of manual modulo
1 parent 733b47e commit 226b0fb

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

compiler/rustc_borrowck/src/polonius/legacy/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ impl PoloniusLocationTable {
109109
impl LocationIndex {
110110
fn is_start(self) -> bool {
111111
// even indices are start points; odd indices are mid points
112-
(self.index() % 2) == 0
112+
self.index().is_multiple_of(2)
113113
}
114114
}

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl LlvmType for CastTarget {
146146
"total size {:?} cannot be divided into units of zero size",
147147
self.rest.total
148148
);
149-
if self.rest.total.bytes() % self.rest.unit.size.bytes() != 0 {
149+
if !self.rest.total.bytes().is_multiple_of(self.rest.unit.size.bytes()) {
150150
assert_eq!(self.rest.unit.kind, RegKind::Integer, "only int regs can be split");
151151
}
152152
self.rest.total.bytes().div_ceil(self.rest.unit.size.bytes())

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
537537

538538
#[inline]
539539
fn is_offset_misaligned(offset: u64, align: Align) -> Option<Misalignment> {
540-
if offset % align.bytes() == 0 {
540+
if offset.is_multiple_of(align.bytes()) {
541541
None
542542
} else {
543543
// The biggest power of two through which `offset` is divisible.
@@ -1554,7 +1554,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
15541554
// If the allocation is N-aligned, and the offset is not divisible by N,
15551555
// then `base + offset` has a non-zero remainder after division by `N`,
15561556
// which means `base + offset` cannot be null.
1557-
if offset.bytes() % info.align.bytes() != 0 {
1557+
if !offset.bytes().is_multiple_of(info.align.bytes()) {
15581558
return interp_ok(false);
15591559
}
15601560
// We don't know enough, this might be null.

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ where
597597
// from disk. Re-hashing results is fairly expensive, so we can't
598598
// currently afford to verify every hash. This subset should still
599599
// give us some coverage of potential bugs though.
600-
let try_verify = prev_fingerprint.split().1.as_u64() % 32 == 0;
600+
let try_verify = prev_fingerprint.split().1.as_u64().is_multiple_of(32);
601601
if std::intrinsics::unlikely(
602602
try_verify || qcx.dep_context().sess().opts.unstable_opts.incremental_verify_ich,
603603
) {

compiler/rustc_target/src/callconv/sparc64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
_ => {}
9191
}
9292

93-
if (offset.bytes() % 4) != 0
93+
if !offset.bytes().is_multiple_of(4)
9494
&& matches!(scalar2.primitive(), Primitive::Float(Float::F32 | Float::F64))
9595
{
9696
offset += Size::from_bytes(4 - (offset.bytes() % 4));
@@ -181,7 +181,7 @@ where
181181
// Structure { float, int, int } doesn't like to be handled like
182182
// { float, long int }. Other way around it doesn't mind.
183183
if data.last_offset < arg.layout.size
184-
&& (data.last_offset.bytes() % 8) != 0
184+
&& !data.last_offset.bytes().is_multiple_of(8)
185185
&& data.prefix_index < data.prefix.len()
186186
{
187187
data.prefix[data.prefix_index] = Some(Reg::i32());
@@ -190,7 +190,7 @@ where
190190
}
191191

192192
let mut rest_size = arg.layout.size - data.last_offset;
193-
if (rest_size.bytes() % 8) != 0 && data.prefix_index < data.prefix.len() {
193+
if !rest_size.bytes().is_multiple_of(8) && data.prefix_index < data.prefix.len() {
194194
data.prefix[data.prefix_index] = Some(Reg::i32());
195195
rest_size = rest_size - Reg::i32().size;
196196
}

compiler/rustc_ty_utils/src/layout/invariant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
88
pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
99
let tcx = cx.tcx();
1010

11-
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
11+
if !layout.size.bytes().is_multiple_of(layout.align.abi.bytes()) {
1212
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
1313
}
1414
if layout.size.bytes() >= tcx.data_layout.obj_size_bound() {

library/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

library/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);

library/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`.

library/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)