1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Fix clippy warnings with Rust 1.72.0

This commit is contained in:
Daniel Hofstetter 2023-08-25 08:12:18 +02:00
parent ffbfea4fa4
commit 01b2834f2e
14 changed files with 22 additions and 18 deletions

View file

@ -33,8 +33,8 @@ use crate::{
fn adjust_canonicalization(p: &Path) -> Cow<Path> { fn adjust_canonicalization(p: &Path) -> Cow<Path> {
// In some cases, \\? can be missing on some Windows paths. Add it at the // In some cases, \\? can be missing on some Windows paths. Add it at the
// beginning unless the path is prefixed with a device namespace. // beginning unless the path is prefixed with a device namespace.
const VERBATIM_PREFIX: &str = r#"\\?"#; const VERBATIM_PREFIX: &str = r"\\?";
const DEVICE_NS_PREFIX: &str = r#"\\."#; const DEVICE_NS_PREFIX: &str = r"\\.";
let has_prefix = p let has_prefix = p
.components() .components()

View file

@ -1133,6 +1133,7 @@ fn preserve_hardlinks(
let inode = get_inode(&info); let inode = get_inode(&info);
let nlinks = info.number_of_links(); let nlinks = info.number_of_links();
let mut found_hard_link = false; let mut found_hard_link = false;
#[allow(clippy::explicit_iter_loop)]
for (link, link_inode) in hard_links.iter() { for (link, link_inode) in hard_links.iter() {
if *link_inode == inode { if *link_inode == inode {
// Consider the following files: // Consider the following files:
@ -1212,7 +1213,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
None None
}; };
for source in sources.iter() { for source in sources {
if seen_sources.contains(source) { 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) // 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()); show_warning!("source {} specified more than once", source.quote());

View file

@ -96,7 +96,7 @@ impl fmt::Display for Factors {
v.sort_unstable(); v.sort_unstable();
let include_exponents = f.alternate(); let include_exponents = f.alternate();
for (p, exp) in v.iter() { for (p, exp) in v {
if include_exponents && *exp > 1 { if include_exponents && *exp > 1 {
write!(f, " {p}^{exp}")?; write!(f, " {p}^{exp}")?;
} else { } else {
@ -292,6 +292,7 @@ impl std::ops::BitXor<Exponent> for Factors {
fn bitxor(self, rhs: Exponent) -> Self { fn bitxor(self, rhs: Exponent) -> Self {
debug_assert_ne!(rhs, 0); debug_assert_ne!(rhs, 0);
let mut r = Self::one(); let mut r = Self::one();
#[allow(clippy::explicit_iter_loop)]
for (p, e) in self.0.borrow().0.iter() { for (p, e) in self.0.borrow().0.iter() {
r.add(*p, rhs * e); r.add(*p, rhs * e);
} }

View file

@ -61,7 +61,7 @@ pub(crate) fn test<A: Arithmetic + Basis>(m: A) -> Result {
let one = m.one(); let one = m.one();
let minus_one = m.minus_one(); let minus_one = m.minus_one();
'witness: for _a in A::BASIS.iter() { 'witness: for _a in A::BASIS {
let _a = _a % n; let _a = _a % n;
if _a == 0 { if _a == 0 {
continue; continue;

View file

@ -273,6 +273,7 @@ fn find_kp_breakpoints<'a, T: Iterator<Item = &'a WordInfo<'a>>>(
next_active_breaks.clear(); next_active_breaks.clear();
// go through each active break, extending it and possibly adding a new active // go through each active break, extending it and possibly adding a new active
// break if we are above the minimum required length // break if we are above the minimum required length
#[allow(clippy::explicit_iter_loop)]
for &i in active_breaks.iter() { for &i in active_breaks.iter() {
let active = &mut linebreaks[i]; let active = &mut linebreaks[i];
// normalize demerits to avoid overflow, and record if this is the least // normalize demerits to avoid overflow, and record if this is the least

View file

@ -297,7 +297,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
} }
let mut all_successful = true; let mut all_successful = true;
for srcpath in files.iter() { for srcpath in files {
let targetpath = let targetpath =
if settings.no_dereference && matches!(settings.overwrite, OverwriteMode::Force) { if settings.no_dereference && matches!(settings.overwrite, OverwriteMode::Force) {
// In that case, we don't want to do link resolution // In that case, we don't want to do link resolution

View file

@ -451,7 +451,7 @@ pub fn dry_exec(tmpdir: &str, prefix: &str, rand: usize, suffix: &str) -> UResul
// Randomize. // Randomize.
let bytes = &mut buf[prefix.len()..prefix.len() + rand]; let bytes = &mut buf[prefix.len()..prefix.len() + rand];
rand::thread_rng().fill(bytes); rand::thread_rng().fill(bytes);
for byte in bytes.iter_mut() { for byte in bytes {
*byte = match *byte % 62 { *byte = match *byte % 62 {
v @ 0..=9 => v + b'0', v @ 0..=9 => v + b'0',
v @ 10..=35 => v - 10 + b'a', v @ 10..=35 => v - 10 + b'a',

View file

@ -322,7 +322,7 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
let reg = Regex::new(&filter.word_regex).unwrap(); let reg = Regex::new(&filter.word_regex).unwrap();
let ref_reg = Regex::new(&config.context_regex).unwrap(); let ref_reg = Regex::new(&config.context_regex).unwrap();
let mut word_set: BTreeSet<WordRef> = BTreeSet::new(); let mut word_set: BTreeSet<WordRef> = BTreeSet::new();
for (file, lines) in file_map.iter() { for (file, lines) in file_map {
let mut count: usize = 0; let mut count: usize = 0;
let offs = lines.offset; let offs = lines.offset;
for line in &lines.lines { for line in &lines.lines {
@ -654,7 +654,7 @@ fn write_traditional_output(
let context_reg = Regex::new(&config.context_regex).unwrap(); 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 let file_map_value: &FileContent = file_map
.get(&(word_ref.filename)) .get(&(word_ref.filename))
.expect("Missing file in file map"); .expect("Missing file in file map");

View file

@ -633,7 +633,7 @@ impl Stater {
Ok(meta) => { Ok(meta) => {
let tokens = &self.default_tokens; let tokens = &self.default_tokens;
for t in tokens.iter() { for t in tokens {
match *t { match *t {
Token::Char(c) => print!("{c}"), Token::Char(c) => print!("{c}"),
Token::Directive { Token::Directive {
@ -701,7 +701,7 @@ impl Stater {
&self.default_dev_tokens &self.default_dev_tokens
}; };
for t in tokens.iter() { for t in tokens {
match *t { match *t {
Token::Char(c) => print!("{c}"), Token::Char(c) => print!("{c}"),
Token::Directive { Token::Directive {

View file

@ -154,6 +154,7 @@ impl Graph {
self.result.push(n.clone()); self.result.push(n.clone());
let n_out_edges = self.out_edges.get_mut(&n).unwrap(); let n_out_edges = self.out_edges.get_mut(&n).unwrap();
#[allow(clippy::explicit_iter_loop)]
for m in n_out_edges.iter() { for m in n_out_edges.iter() {
let m_in_edges = self.in_edges.get_mut(m).unwrap(); let m_in_edges = self.in_edges.get_mut(m).unwrap();
m_in_edges.remove(&n); m_in_edges.remove(&n);

View file

@ -176,7 +176,7 @@ impl Digest for CRC {
} }
fn hash_update(&mut self, input: &[u8]) { fn hash_update(&mut self, input: &[u8]) {
for &elt in input.iter() { for &elt in input {
self.update(elt); self.update(elt);
} }
self.size += input.len(); self.size += input.len();
@ -223,7 +223,7 @@ impl Digest for BSD {
} }
fn hash_update(&mut self, input: &[u8]) { 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 >> 1) + ((self.state & 1) << 15);
self.state = self.state.wrapping_add(u16::from(byte)); self.state = self.state.wrapping_add(u16::from(byte));
} }
@ -257,7 +257,7 @@ impl Digest for SYSV {
} }
fn hash_update(&mut self, input: &[u8]) { 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)); self.state = self.state.wrapping_add(u32::from(byte));
} }
} }

View file

@ -195,7 +195,7 @@ pub fn str_to_arrnum(src: &str, radix_def_src: &dyn RadixDef) -> Vec<u8> {
pub fn arrnum_to_str(src: &[u8], radix_def_dest: &dyn RadixDef) -> String { pub fn arrnum_to_str(src: &[u8], radix_def_dest: &dyn RadixDef) -> String {
let mut str_out = String::new(); let mut str_out = String::new();
for u in src.iter() { for u in src {
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
match radix_def_dest.format_u8(*u) { match radix_def_dest.format_u8(*u) {
Some(c) => { Some(c) => {

View file

@ -188,11 +188,11 @@ impl SubParser {
// though, as we want to mimic the original behavior of printing // though, as we want to mimic the original behavior of printing
// the field as interpreted up until the error in the field. // 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 // 'a', 'A', //c99 hex float implementation not yet complete
'b', 'c', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'i', 'o', 's', 'u', 'x', 'X', '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(); legal_fields.sort_unstable();
specifiers.sort_unstable(); specifiers.sort_unstable();

View file

@ -137,7 +137,7 @@ fn custom_context() {
} }
fn get_sestatus_context(output: &[u8]) -> &str { 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"); .expect("Invalid regular expression");
output output