From faf341201910898dc1d3438031542060bc95008d Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sat, 22 Feb 2025 09:47:15 -0500 Subject: [PATCH] Style fixes from cargo +nightly clippy --- src/bin/coreutils.rs | 2 +- src/uu/expand/src/expand.rs | 2 +- src/uu/mkdir/src/mkdir.rs | 2 +- src/uu/mktemp/src/mktemp.rs | 2 ++ src/uu/sort/src/chunks.rs | 4 ++-- src/uu/tail/src/chunks.rs | 4 ++-- src/uu/tr/src/operation.rs | 2 ++ src/uucore/src/lib/features/checksum.rs | 2 +- src/uucore/src/lib/features/sum.rs | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 5feb6fce4..886c41b4d 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -107,7 +107,7 @@ fn main() { } // Not a special command: fallthrough to calling a util _ => {} - }; + } match utils.get(util) { Some(&(uumain, _)) => { diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 6df282de2..17ab7761b 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -425,7 +425,7 @@ fn expand_line( // now dump out either spaces if we're expanding, or a literal tab if we're not if init || !options.iflag { if nts <= options.tspaces.len() { - output.write_all(options.tspaces[..nts].as_bytes())?; + output.write_all(&options.tspaces.as_bytes()[..nts])?; } else { output.write_all(" ".repeat(nts).as_bytes())?; }; diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 9928271e7..c9d44bec5 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -152,7 +152,7 @@ fn exec(dirs: ValuesRef, recursive: bool, mode: u32, verbose: bool) -> /// ## Options /// /// * `recursive` --- create parent directories for the `path`, if they do not -/// exist. +/// exist. /// * `mode` --- file mode for the directories (not implemented on windows). /// * `verbose` --- print a message for each printed directory. /// diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index cd5d965bc..9859869c8 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -424,6 +424,8 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult

buf.extend(iter::repeat(b'X').take(rand)); buf.extend(suffix.as_bytes()); diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 525a9f66b..86b734796 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -227,12 +227,12 @@ fn parse_lines<'a>( /// /// * `file`: The file to start reading from. /// * `next_files`: When `file` reaches EOF, it is updated to `next_files.next()` if that is `Some`, -/// and this function continues reading. +/// and this function continues reading. /// * `buffer`: The buffer that is filled with bytes. Its contents will mostly be overwritten (see `start_offset` /// as well). It will be grown up to `max_buffer_size` if necessary, but it will always grow to read at least two lines. /// * `max_buffer_size`: Grow the buffer to at most this length. If None, the buffer will not grow, unless needed to read at least two lines. /// * `start_offset`: The amount of bytes at the start of `buffer` that were carried over -/// from the previous read and should not be overwritten. +/// from the previous read and should not be overwritten. /// * `separator`: The byte that separates lines. /// /// # Returns diff --git a/src/uu/tail/src/chunks.rs b/src/uu/tail/src/chunks.rs index 2c80ac0ac..d4c0b63f8 100644 --- a/src/uu/tail/src/chunks.rs +++ b/src/uu/tail/src/chunks.rs @@ -141,7 +141,7 @@ impl BytesChunk { /// /// * `chunk`: The chunk to create a new `BytesChunk` chunk from /// * `offset`: Start to copy the old chunk's buffer from this position. May not be larger - /// than `chunk.bytes`. + /// than `chunk.bytes`. /// /// # Examples /// @@ -477,7 +477,7 @@ impl LinesChunk { /// # Arguments /// /// * `offset`: the offset in number of lines. If offset is 0 then 0 is returned, if larger than - /// the contained lines then self.bytes is returned. + /// the contained lines then self.bytes is returned. /// /// # Examples /// diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index a8c499070..b6b01509c 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -132,6 +132,8 @@ impl Sequence { Self::Char(c) => Box::new(std::iter::once(*c)), Self::CharRange(l, r) => Box::new(*l..=*r), Self::CharStar(c) => Box::new(std::iter::repeat(*c)), + // In Rust v1.82.0, use `repeat_n`: + // Self::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)), Self::Class(class) => match class { Class::Alnum => Box::new((b'0'..=b'9').chain(b'A'..=b'Z').chain(b'a'..=b'z')), diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 8346f9c6d..04c950880 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -1061,7 +1061,7 @@ pub fn digest_reader( Ok((digest.result_str(), output_size)) } else { // Assume it's SHAKE. result_str() doesn't work with shake (as of 8/30/2016) - let mut bytes = vec![0; (output_bits + 7) / 8]; + let mut bytes = vec![0; output_bits.div_ceil(8)]; digest.hash_finalize(&mut bytes); Ok((hex::encode(bytes), output_size)) } diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index 258cb2362..be450cb2f 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -27,7 +27,7 @@ pub trait Digest { fn reset(&mut self); fn output_bits(&self) -> usize; fn output_bytes(&self) -> usize { - (self.output_bits() + 7) / 8 + self.output_bits().div_ceil(8) } fn result_str(&mut self) -> String { let mut buf: Vec = vec![0; self.output_bytes()];