From 0f3f8aea568c08f6ceec19abe24d87dbdb309569 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:46:09 +0100 Subject: [PATCH 1/5] clippy: fix map_unwrap_or lint https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or --- src/uu/cat/src/platform/windows.rs | 4 +--- src/uucore/build.rs | 4 +--- src/uucore/src/lib/features/pipes.rs | 4 +--- tests/by-util/test_df.rs | 6 ++---- tests/uutests/src/lib/util.rs | 3 +-- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/uu/cat/src/platform/windows.rs b/src/uu/cat/src/platform/windows.rs index ebf375b324e..07f5b341679 100644 --- a/src/uu/cat/src/platform/windows.rs +++ b/src/uu/cat/src/platform/windows.rs @@ -20,9 +20,7 @@ pub fn is_unsafe_overwrite(input: &I, output: &O } // Check if the output file is empty - FileInformation::from_file(output) - .map(|info| info.file_size() > 0) - .unwrap_or(false) + FileInformation::from_file(output).is_ok_and(|info| info.file_size() > 0) } /// Get the file path for a file handle diff --git a/src/uucore/build.rs b/src/uucore/build.rs index f3b4df331a7..2aa46d24961 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -350,9 +350,7 @@ fn embed_locale_file( /// Check if we are cross-compiling for WASI (build.rs runs on the host, /// so `#[cfg(target_os = "wasi")]` does not work here). fn is_wasi_target() -> bool { - env::var("CARGO_CFG_TARGET_OS") - .map(|os| os == "wasi") - .unwrap_or(false) + env::var("CARGO_CFG_TARGET_OS").is_ok_and(|os| os == "wasi") } /// For WASI/WASM builds, embed ALL available .ftl files in a locale diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index 24890efca94..c91fa4a0dd0 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -67,9 +67,7 @@ pub fn splice_exact(source: &impl AsFd, target: &impl AsFd, len: usize) -> std:: #[inline] #[cfg(any(target_os = "linux", target_os = "android"))] pub fn might_fuse(source: &impl AsFd) -> bool { - rustix::fs::fstatfs(source) - .map(|stats| stats.f_type == 0x6573_5546) // FUSE magic number, too many platform specific clippy warning with const - .unwrap_or(true) + rustix::fs::fstatfs(source).map_or(true, |stats| stats.f_type == 0x6573_5546) // FUSE magic number, too many platform specific clippy warning with const } /// Return verified /dev/null diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index c1cf50d2518..2ac91d1a11e 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -1054,8 +1054,7 @@ fn test_nonexistent_file() { fn test_df_all_shows_binfmt_misc() { // Check if binfmt_misc is mounted let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") - .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) - .unwrap_or(false); + .is_ok_and(|content| content.lines().any(|line| line.contains("binfmt_misc"))); if is_mounted { let output = new_ucmd!() @@ -1076,8 +1075,7 @@ fn test_df_all_shows_binfmt_misc() { fn test_df_hides_binfmt_misc_by_default() { // Check if binfmt_misc is mounted let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") - .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) - .unwrap_or(false); + .is_ok_and(|content| content.lines().any(|line| line.contains("binfmt_misc"))); if is_mounted { let output = new_ucmd!() diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 834023e4ca7..7887111ca5e 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -109,8 +109,7 @@ pub fn is_locale_available(locale: &str) -> bool { .env("LC_ALL", locale) .arg("charmap") .output() - .map(|o| String::from_utf8_lossy(&o.stdout).trim() == "UTF-8") - .unwrap_or(false) + .is_ok_and(|o| String::from_utf8_lossy(&o.stdout).trim() == "UTF-8") } /// Read a test scenario fixture, returning its bytes From 11ae525e23a385c334d7e80e64edb3c72e060d40 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:52:12 +0100 Subject: [PATCH 2/5] clippy: fix unnecessary_trailing_comma lint https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_trailing_comma --- tests/by-util/test_cksum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 16ed6d8b373..7e661563266 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -3376,7 +3376,7 @@ fn test_check_blake3_tagged( None => String::new(), }; - let tagged = format!("BLAKE3{len} (FILE) = {digest}",); + let tagged = format!("BLAKE3{len} (FILE) = {digest}"); ucmd.arg("-c") .arg("-a") From 0ca09cb626c9b9c5f70e6917606f6a329f2c20d7 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:58:19 +0100 Subject: [PATCH 3/5] clippy: fix unnecessary_cast lint https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast --- src/uucore/src/lib/features/uptime.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index 9709501400b..8d33cd081a2 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -521,11 +521,9 @@ mod tests { ); // Boot time should be before current time - let now = Timestamp::now().as_second(); - assert!( - (boot_time as i64) < now, - "Boot time should be before current time" - ); + let boot_time = Timestamp::from_second(boot_time).unwrap(); + let now = Timestamp::now(); + assert!(boot_time < now, "Boot time should be before current time"); } /// Test that get_uptime always succeeds on macOS due to sysctl fallback. From eafaf1905da420b099426258cac9da7698b32339 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 16 Apr 2026 15:14:37 +0100 Subject: [PATCH 4/5] clippy: fix useless_conversion lint https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion --- src/uu/dd/src/dd.rs | 2 +- src/uu/dircolors/src/dircolors.rs | 2 +- src/uu/od/src/parse_formats.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 72aee399121..678f1769e6e 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -568,7 +568,7 @@ impl Input<'_> { bytes_total += rlen; reads_partial += 1; let padding = vec![pad; target_len - rlen]; - buf.splice(base_idx + rlen..next_blk, padding.into_iter()); + buf.splice(base_idx + rlen..next_blk, padding); } rlen => { bytes_total += rlen; diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 154d879b671..2bf8b517e44 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -364,7 +364,7 @@ where let mut state = ParseState::Global; let mut saw_colorterm_match = false; - for (num, line) in (1..).zip(user_input.into_iter()) { + for (num, line) in (1..).zip(user_input) { let line = line.borrow().purify(); if line.is_empty() { continue; diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index e3312b87603..b6cd91b4d0d 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -121,7 +121,7 @@ pub fn parse_format_flags(args: &[String]) -> Result Result Result Date: Thu, 16 Apr 2026 15:26:52 +0100 Subject: [PATCH 5/5] clippy: fix collapsible_match lint https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match --- src/uu/chcon/src/chcon.rs | 58 +++++++++++++--------------- src/uu/cp/src/cp.rs | 6 +-- src/uu/date/src/format_modifiers.rs | 8 ++-- src/uu/od/src/od.rs | 59 ++++++++++++++--------------- src/uu/tail/src/follow/watch.rs | 5 +-- src/uucore/src/lib/features/fs.rs | 11 +++--- 6 files changed, 67 insertions(+), 80 deletions(-) diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 9953c064fd3..c1e66d44c94 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -537,33 +537,29 @@ fn process_file( let mut result = Ok(()); match entry.flags() { - fts_sys::FTS_D => { - if options.recursive_mode.is_recursive() { - if root_dev_ino_check(root_dev_ino, file_dev_ino) { - // This happens e.g., with "chcon -R --preserve-root ... /" - // and with "chcon -RH --preserve-root ... symlink-to-root". - root_dev_ino_warn(&file_full_name); - - // Tell fts not to traverse into this hierarchy. - let _ignored = fts.set(fts_sys::FTS_SKIP); - - // Ensure that we do not process "/" on the second visit. - let _ignored = fts.read_next_entry(); - - return Err(err( - translate!("chcon-op-modifying-root-path"), - io::ErrorKind::PermissionDenied, - )); - } + fts_sys::FTS_D if options.recursive_mode.is_recursive() => { + if root_dev_ino_check(root_dev_ino, file_dev_ino) { + // This happens e.g., with "chcon -R --preserve-root ... /" + // and with "chcon -RH --preserve-root ... symlink-to-root". + root_dev_ino_warn(&file_full_name); - return Ok(()); + // Tell fts not to traverse into this hierarchy. + let _ignored = fts.set(fts_sys::FTS_SKIP); + + // Ensure that we do not process "/" on the second visit. + let _ignored = fts.read_next_entry(); + + return Err(err( + translate!("chcon-op-modifying-root-path"), + io::ErrorKind::PermissionDenied, + )); } + + return Ok(()); } - fts_sys::FTS_DP => { - if !options.recursive_mode.is_recursive() { - return Ok(()); - } + fts_sys::FTS_DP if !options.recursive_mode.is_recursive() => { + return Ok(()); } fts_sys::FTS_NS => { @@ -585,14 +581,14 @@ fn process_file( fts_sys::FTS_DNR => result = fts_err(translate!("chcon-op-reading-directory")), - fts_sys::FTS_DC => { - if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) { - emit_cycle_warning(&file_full_name); - return Err(err( - translate!("chcon-op-reading-cyclic-directory"), - io::ErrorKind::InvalidData, - )); - } + fts_sys::FTS_DC + if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) => + { + emit_cycle_warning(&file_full_name); + return Err(err( + translate!("chcon-op-reading-cyclic-directory"), + io::ErrorKind::InvalidData, + )); } _ => {} diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 9f023a3937f..2e9ae6b62ef 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1134,10 +1134,8 @@ impl Options { options::PRESERVE => { attributes = attributes.union(&Attributes::parse_iter(val.into_iter())?); } - options::NO_PRESERVE => { - if !val.is_empty() { - attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?); - } + options::NO_PRESERVE if !val.is_empty() => { + attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?); } _ => (), } diff --git a/src/uu/date/src/format_modifiers.rs b/src/uu/date/src/format_modifiers.rs index fd269379a42..bd87f464786 100644 --- a/src/uu/date/src/format_modifiers.rs +++ b/src/uu/date/src/format_modifiers.rs @@ -379,11 +379,9 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result { - if !uppercase { - // Only apply # if ^ hasn't been set - swap_case = true; - } + '#' if !uppercase => { + // Only apply # if ^ hasn't been set + swap_case = true; } '+' => { force_sign = true; diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 1a16b9276dd..7762048ea3e 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -132,38 +132,35 @@ impl OdOptions { let formats = parse_format_flags(args).map_err(|e| USimpleError::new(1, e))?; - let mut line_bytes = match matches.get_one::(options::WIDTH) { - None => 16, - Some(s) => { - if matches.value_source(options::WIDTH) == Some(ValueSource::CommandLine) { - let width_display = option_display_name(args, options::WIDTH, Some('w')); - let parsed = parse_number_of_bytes(s).map_err(|e| { - USimpleError::new(1, format_error_message(&e, s, &width_display)) - })?; - if parsed == 0 { - return Err(USimpleError::new( - 1, - translate!( - "od-error-invalid-argument", - "option" => width_display.clone(), - "value" => s.quote() - ), - )); - } - usize::try_from(parsed).map_err(|_| { - USimpleError::new( - 1, - translate!( - "od-error-argument-too-large", - "option" => width_display.clone(), - "value" => s.quote() - ), - ) - })? - } else { - 16 - } + let mut line_bytes = if let (Some(s), Some(ValueSource::CommandLine)) = ( + matches.get_one::(options::WIDTH), + matches.value_source(options::WIDTH), + ) { + let width_display = option_display_name(args, options::WIDTH, Some('w')); + let parsed = parse_number_of_bytes(s) + .map_err(|e| USimpleError::new(1, format_error_message(&e, s, &width_display)))?; + if parsed == 0 { + return Err(USimpleError::new( + 1, + translate!( + "od-error-invalid-argument", + "option" => width_display.clone(), + "value" => s.quote() + ), + )); } + usize::try_from(parsed).map_err(|_| { + USimpleError::new( + 1, + translate!( + "od-error-argument-too-large", + "option" => width_display.clone(), + "value" => s.quote() + ), + ) + })? + } else { + 16 }; let min_bytes = formats.iter().fold(1, |max, next| { diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index c38f2d081dd..7300e954087 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -439,7 +439,7 @@ impl Observer { */ } } - EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => { + EventKind::Modify(ModifyKind::Name(RenameMode::Both)) /* NOTE: For `tail -f a`, keep tracking additions to b after `mv a b` (gnu/tests/tail-2/descriptor-vs-rename.sh) @@ -457,7 +457,7 @@ impl Observer { TODO: [2022-05; jhscheer] add test for this bug */ - if self.follow_descriptor() { + if self.follow_descriptor() => { let new_path = event.paths.last().unwrap(); paths.push(new_path.clone()); @@ -472,7 +472,6 @@ impl Observer { let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path); self.watcher_rx.as_mut().unwrap().watch_with_parent(new_path)?; } - } _ => {} } Ok(paths) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 0f2b37dc176..d165b8a9f68 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -435,12 +435,11 @@ pub fn canonicalize>( } result.pop(); } - Err(e) => { - if miss_mode == MissingHandling::Existing - || (miss_mode == MissingHandling::Normal && !parts.is_empty()) - { - return Err(e); - } + Err(e) + if (miss_mode == MissingHandling::Existing + || (miss_mode == MissingHandling::Normal && !parts.is_empty())) => + { + return Err(e); } _ => {} }