Skip to content

Commit c73b3ab

Browse files
authored
clippy: fix manual_is_multiple_of lint (#10775)
* clippy: fix manual_is_multiple_of lint https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of * fmt * taplo
1 parent 31c5102 commit c73b3ab

File tree

7 files changed

+13
-17
lines changed

7 files changed

+13
-17
lines changed

.cargo/config.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,4 @@ LIBSTDBUF_DIR = "/usr/local/libexec/coreutils"
1515

1616
# remove me
1717
[build]
18-
rustflags = [
19-
"-A",
20-
"clippy::collapsible_if",
21-
"-A",
22-
"clippy::manual_is_multiple_of",
23-
]
18+
rustflags = ["-A", "clippy::collapsible_if"]

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
642642
unused_qualifications = "warn"
643643

644644
[workspace.lints.clippy]
645-
manual_is_multiple_of = { level = "allow", priority = 127 } # remove me
646-
collapsible_if = { level = "allow", priority = 127 } # remove me
645+
collapsible_if = { level = "allow", priority = 127 } # remove me
647646
# The counts were generated with this command:
648647
# cargo clippy --all-targets --workspace --message-format=json --quiet \
649648
# | jq -r '.message.code.code | select(. != null and startswith("clippy::"))' \

src/uu/df/src/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(crate) fn to_magnitude_and_suffix(
107107

108108
if quot >= 100 && rem > 0 {
109109
format!("{}{suffix}", quot + 1)
110-
} else if rem % (bases[i] / 10) == 0 {
110+
} else if rem.is_multiple_of(bases[i] / 10) {
111111
format!("{quot}.{tenths_place}{suffix}")
112112
} else if tenths_place + 1 == 10 || quot >= 10 {
113113
let quot = quot + 1;

src/uu/nl/src/nl.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl SectionDelimiter {
172172
fn parse(bytes: &[u8], pattern: &OsStr) -> Option<Self> {
173173
let pattern = pattern.as_encoded_bytes();
174174

175-
if bytes.is_empty() || pattern.is_empty() || bytes.len() % pattern.len() != 0 {
175+
if bytes.is_empty() || pattern.is_empty() || !bytes.len().is_multiple_of(pattern.len()) {
176176
return None;
177177
}
178178

@@ -426,7 +426,9 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
426426
NumberingStyle::All
427427
if line.is_empty()
428428
&& settings.join_blank_lines > 0
429-
&& stats.consecutive_empty_lines % settings.join_blank_lines != 0 =>
429+
&& !stats
430+
.consecutive_empty_lines
431+
.is_multiple_of(settings.join_blank_lines) =>
430432
{
431433
false
432434
}

src/uu/wc/src/count_fast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
136136
&& stat.st_size > 0
137137
{
138138
let sys_page_size = unsafe { sysconf(_SC_PAGESIZE) as usize };
139-
if stat.st_size as usize % sys_page_size > 0 {
139+
if !(stat.st_size as usize).is_multiple_of(sys_page_size) {
140140
// regular file or file from /proc, /sys and similar pseudo-filesystems
141141
// with size that is NOT a multiple of system page size
142142
return (stat.st_size as usize, None);

src/uucore/src/lib/features/checksum/validate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl LineFormat {
417417
// checksums that are fully alphanumeric. Another check happens later
418418
// when we are provided with a length hint to detect ambiguous
419419
// base64-encoded checksums.
420-
if is_base64 && checksum.len() % 4 != 0 {
420+
if is_base64 && !checksum.len().is_multiple_of(4) {
421421
return None;
422422
}
423423

@@ -493,7 +493,7 @@ fn get_raw_expected_digest(checksum: &str, byte_len_hint: Option<usize>) -> Opti
493493
// If the length of the digest is not a multiple of 2, then it must be
494494
// improperly formatted (1 byte is 2 hex digits, and base64 strings should
495495
// always be a multiple of 4).
496-
if checksum.len() % 2 != 0 {
496+
if !checksum.len().is_multiple_of(2) {
497497
return None;
498498
}
499499

@@ -516,7 +516,7 @@ fn get_raw_expected_digest(checksum: &str, byte_len_hint: Option<usize>) -> Opti
516516
// It is important to check it before trying to decode, because the
517517
// forgiving mode of decoding will ignore if padding characters '=' are
518518
// MISSING, but to match GNU's behavior, we must reject it.
519-
if checksum.len() % 4 != 0 {
519+
if !checksum.len().is_multiple_of(4) {
520520
return None;
521521
}
522522

src/uucore/src/lib/features/encoding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper {
100100
// If there are no more '=' bytes the tail might still be padded
101101
// (len % 4 == 0) or purposely unpadded (GNU --ignore-garbage or
102102
// concatenated streams), so select the matching alphabet.
103-
let decoder = if remaining.len() % 4 == 0 {
103+
let decoder = if remaining.len().is_multiple_of(4) {
104104
Self::decode_with_standard
105105
} else {
106106
Self::decode_with_no_pad
@@ -448,7 +448,7 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper {
448448
fn encode_to_vec_deque(&self, input: &[u8], output: &mut VecDeque<u8>) -> UResult<()> {
449449
// According to the spec we should not accept inputs whose len is not a multiple of 4.
450450
// However, the z85 crate implements a padded encoding and accepts such inputs. We have to manually check for them.
451-
if input.len() % 4 != 0 {
451+
if !input.len().is_multiple_of(4) {
452452
return Err(USimpleError::new(
453453
1,
454454
"error: invalid input (length must be multiple of 4 characters)".to_owned(),

0 commit comments

Comments
 (0)