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
This commit is contained in:
xtqqczze
2026-02-07 13:42:18 +00:00
committed by GitHub
parent 31c5102bee
commit c73b3ab2e6
7 changed files with 13 additions and 17 deletions
+1 -6
View File
@@ -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"]
+1 -2
View File
@@ -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::"))' \
+1 -1
View File
@@ -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;
+4 -2
View File
@@ -172,7 +172,7 @@ impl SectionDelimiter {
fn parse(bytes: &[u8], pattern: &OsStr) -> Option<Self> {
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<T: Read>(reader: &mut BufReader<T>, 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
}
+1 -1
View File
@@ -136,7 +136,7 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(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);
@@ -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<usize>) -> 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<usize>) -> 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;
}
+2 -2
View File
@@ -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<u8>) -> 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(),