diff --git a/.cargo/config.toml b/.cargo/config.toml index 32631f68400..f3a0a563efd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -15,9 +15,4 @@ LIBSTDBUF_DIR = "/usr/local/libexec/coreutils" # remove me [build] -rustflags = [ - "-A", - "clippy::collapsible_if", - "-A", - "clippy::manual_is_multiple_of", -] +rustflags = ["-A", "clippy::collapsible_if"] diff --git a/Cargo.toml b/Cargo.toml index d253149b3cf..520c7d203e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -642,8 +642,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ unused_qualifications = "warn" [workspace.lints.clippy] -manual_is_multiple_of = { level = "allow", priority = 127 } # remove me -collapsible_if = { level = "allow", priority = 127 } # remove me +collapsible_if = { level = "allow", priority = 127 } # remove me # The counts were generated with this command: # cargo clippy --all-targets --workspace --message-format=json --quiet \ # | jq -r '.message.code.code | select(. != null and startswith("clippy::"))' \ diff --git a/src/uu/df/src/blocks.rs b/src/uu/df/src/blocks.rs index 328090ffded..24ebbf44225 100644 --- a/src/uu/df/src/blocks.rs +++ b/src/uu/df/src/blocks.rs @@ -107,7 +107,7 @@ pub(crate) fn to_magnitude_and_suffix( if quot >= 100 && rem > 0 { format!("{}{suffix}", quot + 1) - } else if rem % (bases[i] / 10) == 0 { + } else if rem.is_multiple_of(bases[i] / 10) { format!("{quot}.{tenths_place}{suffix}") } else if tenths_place + 1 == 10 || quot >= 10 { let quot = quot + 1; diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 5288aaefbce..616f8d4100d 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -172,7 +172,7 @@ impl SectionDelimiter { fn parse(bytes: &[u8], pattern: &OsStr) -> Option { let pattern = pattern.as_encoded_bytes(); - if bytes.is_empty() || pattern.is_empty() || bytes.len() % pattern.len() != 0 { + if bytes.is_empty() || pattern.is_empty() || !bytes.len().is_multiple_of(pattern.len()) { return None; } @@ -426,7 +426,9 @@ fn nl(reader: &mut BufReader, stats: &mut Stats, settings: &Settings NumberingStyle::All if line.is_empty() && settings.join_blank_lines > 0 - && stats.consecutive_empty_lines % settings.join_blank_lines != 0 => + && !stats + .consecutive_empty_lines + .is_multiple_of(settings.join_blank_lines) => { false } diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index d20c53d4fb8..5e2ecd080a0 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -136,7 +136,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti && stat.st_size > 0 { let sys_page_size = unsafe { sysconf(_SC_PAGESIZE) as usize }; - if stat.st_size as usize % sys_page_size > 0 { + if !(stat.st_size as usize).is_multiple_of(sys_page_size) { // regular file or file from /proc, /sys and similar pseudo-filesystems // with size that is NOT a multiple of system page size return (stat.st_size as usize, None); diff --git a/src/uucore/src/lib/features/checksum/validate.rs b/src/uucore/src/lib/features/checksum/validate.rs index 7fede1c4978..64dc476312b 100644 --- a/src/uucore/src/lib/features/checksum/validate.rs +++ b/src/uucore/src/lib/features/checksum/validate.rs @@ -417,7 +417,7 @@ impl LineFormat { // checksums that are fully alphanumeric. Another check happens later // when we are provided with a length hint to detect ambiguous // base64-encoded checksums. - if is_base64 && checksum.len() % 4 != 0 { + if is_base64 && !checksum.len().is_multiple_of(4) { return None; } @@ -493,7 +493,7 @@ fn get_raw_expected_digest(checksum: &str, byte_len_hint: Option) -> Opti // If the length of the digest is not a multiple of 2, then it must be // improperly formatted (1 byte is 2 hex digits, and base64 strings should // always be a multiple of 4). - if checksum.len() % 2 != 0 { + if !checksum.len().is_multiple_of(2) { return None; } @@ -516,7 +516,7 @@ fn get_raw_expected_digest(checksum: &str, byte_len_hint: Option) -> Opti // It is important to check it before trying to decode, because the // forgiving mode of decoding will ignore if padding characters '=' are // MISSING, but to match GNU's behavior, we must reject it. - if checksum.len() % 4 != 0 { + if !checksum.len().is_multiple_of(4) { return None; } diff --git a/src/uucore/src/lib/features/encoding.rs b/src/uucore/src/lib/features/encoding.rs index 2f7caae2b78..635f595e81e 100644 --- a/src/uucore/src/lib/features/encoding.rs +++ b/src/uucore/src/lib/features/encoding.rs @@ -100,7 +100,7 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper { // If there are no more '=' bytes the tail might still be padded // (len % 4 == 0) or purposely unpadded (GNU --ignore-garbage or // concatenated streams), so select the matching alphabet. - let decoder = if remaining.len() % 4 == 0 { + let decoder = if remaining.len().is_multiple_of(4) { Self::decode_with_standard } else { Self::decode_with_no_pad @@ -448,7 +448,7 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper { fn encode_to_vec_deque(&self, input: &[u8], output: &mut VecDeque) -> UResult<()> { // According to the spec we should not accept inputs whose len is not a multiple of 4. // However, the z85 crate implements a padded encoding and accepts such inputs. We have to manually check for them. - if input.len() % 4 != 0 { + if !input.len().is_multiple_of(4) { return Err(USimpleError::new( 1, "error: invalid input (length must be multiple of 4 characters)".to_owned(),