From 6f5610bc032dc1b4769d6deb6b083d4743cedd18 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 25 Aug 2023 08:12:18 +0200 Subject: [PATCH] Fix clippy warnings with Rust 1.72.0 --- src/uu/cp/src/cp.rs | 4 ++-- src/uu/factor/src/factor.rs | 4 ++-- src/uu/factor/src/miller_rabin.rs | 2 +- src/uu/fmt/src/linebreak.rs | 2 +- src/uu/ln/src/ln.rs | 2 +- src/uu/mktemp/src/mktemp.rs | 2 +- src/uu/ptx/src/ptx.rs | 4 ++-- src/uu/stat/src/stat.rs | 4 ++-- src/uu/tsort/src/tsort.rs | 2 +- src/uucore/src/lib/features/sum.rs | 6 +++--- .../tokenize/num_format/formatters/base_conv/mod.rs | 2 +- src/uucore/src/lib/features/tokenize/sub.rs | 4 ++-- tests/by-util/test_runcon.rs | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 4b326d9d52e..d68af90b719 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1133,7 +1133,7 @@ fn preserve_hardlinks( let inode = get_inode(&info); let nlinks = info.number_of_links(); let mut found_hard_link = false; - for (link, link_inode) in hard_links.iter() { + for (link, link_inode) in &*hard_links { if *link_inode == inode { // Consider the following files: // @@ -1212,7 +1212,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult None }; - for source in sources.iter() { + for source in sources { if seen_sources.contains(source) { // FIXME: compare sources by the actual file they point to, not their path. (e.g. dir/file == dir/../dir/file in most cases) show_warning!("source {} specified more than once", source.quote()); diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 1af6bc55091..4a527f2657b 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -96,7 +96,7 @@ impl fmt::Display for Factors { v.sort_unstable(); let include_exponents = f.alternate(); - for (p, exp) in v.iter() { + for (p, exp) in &*v { if include_exponents && *exp > 1 { write!(f, " {p}^{exp}")?; } else { @@ -292,7 +292,7 @@ impl std::ops::BitXor for Factors { fn bitxor(self, rhs: Exponent) -> Self { debug_assert_ne!(rhs, 0); let mut r = Self::one(); - for (p, e) in self.0.borrow().0.iter() { + for (p, e) in &self.0.borrow().0 { r.add(*p, rhs * e); } diff --git a/src/uu/factor/src/miller_rabin.rs b/src/uu/factor/src/miller_rabin.rs index 1ccc5560044..a06b20cd3b0 100644 --- a/src/uu/factor/src/miller_rabin.rs +++ b/src/uu/factor/src/miller_rabin.rs @@ -61,7 +61,7 @@ pub(crate) fn test(m: A) -> Result { let one = m.one(); let minus_one = m.minus_one(); - 'witness: for _a in A::BASIS.iter() { + 'witness: for _a in A::BASIS { let _a = _a % n; if _a == 0 { continue; diff --git a/src/uu/fmt/src/linebreak.rs b/src/uu/fmt/src/linebreak.rs index 13f34ca96e1..29961c7504f 100644 --- a/src/uu/fmt/src/linebreak.rs +++ b/src/uu/fmt/src/linebreak.rs @@ -273,7 +273,7 @@ fn find_kp_breakpoints<'a, T: Iterator>>( next_active_breaks.clear(); // go through each active break, extending it and possibly adding a new active // break if we are above the minimum required length - for &i in active_breaks.iter() { + for &i in &*active_breaks { let active = &mut linebreaks[i]; // normalize demerits to avoid overflow, and record if this is the least active.demerits -= least_demerits; diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 18d515a88b2..8b76aa73c0b 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -297,7 +297,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) } let mut all_successful = true; - for srcpath in files.iter() { + for srcpath in files { let targetpath = if settings.no_dereference && matches!(settings.overwrite, OverwriteMode::Force) { // In that case, we don't want to do link resolution diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index f99136810d1..587351de0e0 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -451,7 +451,7 @@ pub fn dry_exec(tmpdir: &str, prefix: &str, rand: usize, suffix: &str) -> UResul // Randomize. let bytes = &mut buf[prefix.len()..prefix.len() + rand]; rand::thread_rng().fill(bytes); - for byte in bytes.iter_mut() { + for byte in &mut *bytes { *byte = match *byte % 62 { v @ 0..=9 => v + b'0', v @ 10..=35 => v - 10 + b'a', diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 4385ab484f5..1e9532a3a12 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -322,7 +322,7 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) -> let reg = Regex::new(&filter.word_regex).unwrap(); let ref_reg = Regex::new(&config.context_regex).unwrap(); let mut word_set: BTreeSet = BTreeSet::new(); - for (file, lines) in file_map.iter() { + for (file, lines) in file_map { let mut count: usize = 0; let offs = lines.offset; for line in &lines.lines { @@ -654,7 +654,7 @@ fn write_traditional_output( let context_reg = Regex::new(&config.context_regex).unwrap(); - for word_ref in words.iter() { + for word_ref in words { let file_map_value: &FileContent = file_map .get(&(word_ref.filename)) .expect("Missing file in file map"); diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 19fc5370a51..c36b450067b 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -633,7 +633,7 @@ impl Stater { Ok(meta) => { let tokens = &self.default_tokens; - for t in tokens.iter() { + for t in tokens { match *t { Token::Char(c) => print!("{c}"), Token::Directive { @@ -701,7 +701,7 @@ impl Stater { &self.default_dev_tokens }; - for t in tokens.iter() { + for t in tokens { match *t { Token::Char(c) => print!("{c}"), Token::Directive { diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index f094963dcc1..689bad3e748 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -154,7 +154,7 @@ impl Graph { self.result.push(n.clone()); let n_out_edges = self.out_edges.get_mut(&n).unwrap(); - for m in n_out_edges.iter() { + for m in &*n_out_edges { let m_in_edges = self.in_edges.get_mut(m).unwrap(); m_in_edges.remove(&n); diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index 2b69008de82..e079d7a30e3 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -176,7 +176,7 @@ impl Digest for CRC { } fn hash_update(&mut self, input: &[u8]) { - for &elt in input.iter() { + for &elt in input { self.update(elt); } self.size += input.len(); @@ -223,7 +223,7 @@ impl Digest for BSD { } fn hash_update(&mut self, input: &[u8]) { - for &byte in input.iter() { + for &byte in input { self.state = (self.state >> 1) + ((self.state & 1) << 15); self.state = self.state.wrapping_add(u16::from(byte)); } @@ -257,7 +257,7 @@ impl Digest for SYSV { } fn hash_update(&mut self, input: &[u8]) { - for &byte in input.iter() { + for &byte in input { self.state = self.state.wrapping_add(u32::from(byte)); } } diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs index f8b5da86c21..7c041fec8c0 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/base_conv/mod.rs @@ -195,7 +195,7 @@ pub fn str_to_arrnum(src: &str, radix_def_src: &dyn RadixDef) -> Vec { pub fn arrnum_to_str(src: &[u8], radix_def_dest: &dyn RadixDef) -> String { let mut str_out = String::new(); - for u in src.iter() { + for u in src { #[allow(clippy::single_match)] match radix_def_dest.format_u8(*u) { Some(c) => { diff --git a/src/uucore/src/lib/features/tokenize/sub.rs b/src/uucore/src/lib/features/tokenize/sub.rs index 4651dc8d859..447616ae6a6 100644 --- a/src/uucore/src/lib/features/tokenize/sub.rs +++ b/src/uucore/src/lib/features/tokenize/sub.rs @@ -188,11 +188,11 @@ impl SubParser { // though, as we want to mimic the original behavior of printing // the field as interpreted up until the error in the field. - let mut legal_fields = vec![ + let mut legal_fields = [ // 'a', 'A', //c99 hex float implementation not yet complete 'b', 'c', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'i', 'o', 's', 'u', 'x', 'X', ]; - let mut specifiers = vec!['h', 'j', 'l', 'L', 't', 'z']; + let mut specifiers = ['h', 'j', 'l', 'L', 't', 'z']; legal_fields.sort_unstable(); specifiers.sort_unstable(); diff --git a/tests/by-util/test_runcon.rs b/tests/by-util/test_runcon.rs index 7635fea49cb..8e8b9b6b562 100644 --- a/tests/by-util/test_runcon.rs +++ b/tests/by-util/test_runcon.rs @@ -137,7 +137,7 @@ fn custom_context() { } fn get_sestatus_context(output: &[u8]) -> &str { - let re = regex::bytes::Regex::new(r#"Current context:\s*(\S+)\s*"#) + let re = regex::bytes::Regex::new(r"Current context:\s*(\S+)\s*") .expect("Invalid regular expression"); output