From beb56b10ab0aaddc8aa6ac58b00773feb6c186e7 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 3 Dec 2024 22:34:14 +0100 Subject: [PATCH 1/2] clippy: fix clippy warnings See: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or --- src/uu/chcon/src/chcon.rs | 2 +- src/uu/du/src/du.rs | 2 +- src/uu/fold/src/fold.rs | 2 +- src/uu/tail/src/args.rs | 4 ++-- src/uu/tail/src/paths.rs | 4 ++-- src/uu/uniq/src/uniq.rs | 2 +- src/uucore/src/lib/features/fs.rs | 2 +- src/uuhelp_parser/src/lib.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index c8d1c4017..b5b892f6c 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -727,7 +727,7 @@ fn get_root_dev_ino() -> Result { } fn root_dev_ino_check(root_dev_ino: Option, dir_dev_ino: DeviceAndINode) -> bool { - root_dev_ino.map_or(false, |root_dev_ino| root_dev_ino == dir_dev_ino) + root_dev_ino == Some(dir_dev_ino) } fn root_dev_ino_warn(dir_name: &Path) { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index d4bec77ef..2392497a9 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -533,7 +533,7 @@ impl StatPrinter { if !self .threshold - .map_or(false, |threshold| threshold.should_exclude(size)) + .is_some_and(|threshold| threshold.should_exclude(size)) && self .max_depth .map_or(true, |max_depth| stat_info.depth <= max_depth) diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 0223248be..e17ba21c3 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -99,7 +99,7 @@ pub fn uu_app() -> Command { fn handle_obsolete(args: &[String]) -> (Vec, Option) { for (i, arg) in args.iter().enumerate() { let slice = &arg; - if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) { + if slice.starts_with('-') && slice.chars().nth(1).is_some_and(|c| c.is_ascii_digit()) { let mut v = args.to_vec(); v.remove(i); return (v, Some(slice[1..].to_owned())); diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index 5cadac608..24b064d1b 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -336,11 +336,11 @@ impl Settings { let blocking_stdin = self.pid == 0 && self.follow == Some(FollowMode::Descriptor) && self.num_inputs() == 1 - && Handle::stdin().map_or(false, |handle| { + && Handle::stdin().is_ok_and(|handle| { handle .as_file() .metadata() - .map_or(false, |meta| !meta.is_file()) + .is_ok_and(|meta| !meta.is_file()) }); if !blocking_stdin && std::io::stdin().is_terminal() { diff --git a/src/uu/tail/src/paths.rs b/src/uu/tail/src/paths.rs index 117cab8b0..4a680943c 100644 --- a/src/uu/tail/src/paths.rs +++ b/src/uu/tail/src/paths.rs @@ -93,7 +93,7 @@ impl Input { pub fn is_tailable(&self) -> bool { match &self.kind { InputKind::File(path) => path_is_tailable(path), - InputKind::Stdin => self.resolve().map_or(false, |path| path_is_tailable(&path)), + InputKind::Stdin => self.resolve().is_some_and(|path| path_is_tailable(&path)), } } } @@ -233,7 +233,7 @@ impl PathExtTail for Path { } pub fn path_is_tailable(path: &Path) -> bool { - path.is_file() || path.exists() && path.metadata().map_or(false, |meta| meta.is_tailable()) + path.is_file() || path.exists() && path.metadata().is_ok_and(|meta| meta.is_tailable()) } #[inline] diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 4084a7b3f..b9090cd50 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -383,7 +383,7 @@ fn should_extract_obs_skip_chars( && posix_version().is_some_and(|v| v <= OBSOLETE) && !preceding_long_opt_req_value && !preceding_short_opt_req_value - && slice.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) + && slice.chars().nth(1).is_some_and(|c| c.is_ascii_digit()) } /// Helper function to [`filter_args`] diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index beb4d77a9..e2958232f 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -710,7 +710,7 @@ pub fn path_ends_with_terminator(path: &Path) -> bool { path.as_os_str() .as_bytes() .last() - .map_or(false, |&byte| byte == b'/' || byte == b'\\') + .is_some_and(|&byte| byte == b'/' || byte == b'\\') } #[cfg(windows)] diff --git a/src/uuhelp_parser/src/lib.rs b/src/uuhelp_parser/src/lib.rs index da50c037b..0e0907f8a 100644 --- a/src/uuhelp_parser/src/lib.rs +++ b/src/uuhelp_parser/src/lib.rs @@ -73,7 +73,7 @@ pub fn parse_usage(content: &str) -> String { pub fn parse_section(section: &str, content: &str) -> Option { fn is_section_header(line: &str, section: &str) -> bool { line.strip_prefix("##") - .map_or(false, |l| l.trim().to_lowercase() == section) + .is_some_and(|l| l.trim().to_lowercase() == section) } let section = §ion.to_lowercase(); From 7708f6e39a50e29ba59643daed8cc84cc188a937 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 17 Dec 2024 22:47:45 +0100 Subject: [PATCH 2/2] clippy: replace .as_bytes().len() => .len() --- src/uu/split/src/split.rs | 2 +- src/uu/tac/src/tac.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 86fded1d5..279e91dae 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -492,7 +492,7 @@ impl Settings { } match first.as_str() { "\\0" => b'\0', - s if s.as_bytes().len() == 1 => s.as_bytes()[0], + s if s.len() == 1 => s.as_bytes()[0], s => return Err(SettingsError::MultiCharacterSeparator(s.to_string())), } } diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 3865c61ae..d1eca4706 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -184,7 +184,7 @@ fn buffer_tac(data: &[u8], before: bool, separator: &str) -> std::io::Result<()> let mut out = BufWriter::new(out.lock()); // The number of bytes in the line separator. - let slen = separator.as_bytes().len(); + let slen = separator.len(); // The index of the start of the next line in the `data`. //