From 0626a4d103107e33fa92c3ca6aef328ba4dff766 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] 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 ebf375b32..07f5b3416 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 f3b4df331..2aa46d249 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 24890efca..c91fa4a0d 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 c1cf50d25..2ac91d1a1 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 834023e4c..7887111ca 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