From a6874d111e898075fd2fbb27bb47c87041bc6a6d Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 17 Nov 2024 15:27:17 +0900 Subject: [PATCH] Fix clippy::unnecessary_map_or warning ``` error: this `map_or` is redundant --> src/cargo.rs:84:41 | 84 | need_doctest_in_workspace = cmd!(config.cargo(), "-Z", "help") | _________________________________________^ 85 | | .read() 86 | | .map_or(false, |s| s.contains("doctest-in-workspace")); | |______________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or = note: `-D clippy::unnecessary-map-or` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_or)]` help: use is_ok_and instead | 84 ~ need_doctest_in_workspace = cmd!(config.cargo(), "-Z", "help") 85 ~ .read().is_ok_and(|s| s.contains("doctest-in-workspace")); | error: this `map_or` is redundant --> src/context.rs:156:24 | 156 | if cmd!("rustup", "toolchain", "list") | ________________________^ 157 | | .read() 158 | | .map_or(false, |t| t.contains(toolchain)) | |_________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_ok_and instead | 156 ~ if cmd!("rustup", "toolchain", "list") 157 + .read().is_ok_and(|t| t.contains(toolchain)) | error: this `map_or` is redundant --> src/main.rs:701:24 | 701 | if p.file_name() | ________________________^ 702 | | .map_or(false, |f| f == "incremental" || f == ".fingerprint" || f == "out") | |___________________________________________________________________________________________________^ help: use is_some_and instead: `p.file_name().is_some_and(|f| f == "incremental" || f == ".fingerprint" || f == "out")` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or error: this `map_or` is redundant --> src/main.rs:1313:20 | 1313 | if p.extension().map_or(false, |e| e == "rs") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `p.extension().is_some_and(|e| e == "rs")` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or ``` --- src/cargo.rs | 2 +- src/context.rs | 2 +- src/main.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index da2c6806..17b48cab 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -83,7 +83,7 @@ impl Workspace { if doctests { need_doctest_in_workspace = cmd!(config.cargo(), "-Z", "help") .read() - .map_or(false, |s| s.contains("doctest-in-workspace")); + .is_some_and(|s| s.contains("doctest-in-workspace")); } let target_dir = diff --git a/src/context.rs b/src/context.rs index 0efdc6af..e037bb6f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -155,7 +155,7 @@ impl Context { let toolchain = sysroot.file_name().unwrap(); if cmd!("rustup", "toolchain", "list") .read() - .map_or(false, |t| t.contains(toolchain)) + .is_some_and(|t| t.contains(toolchain)) { // If toolchain is installed from rustup and llvm-tools-preview is not installed, // suggest installing llvm-tools-preview via rustup. diff --git a/src/main.rs b/src/main.rs index 901fa88a..534a6f47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -699,7 +699,7 @@ fn object_files(cx: &Context) -> Result> { let p = e.path(); if p.is_dir() { if p.file_name() - .map_or(false, |f| f == "incremental" || f == ".fingerprint" || f == "out") + .is_some_and(|f| f == "incremental" || f == ".fingerprint" || f == "out") { // Ignore incremental compilation related files and output from build scripts. return false; @@ -1310,7 +1310,7 @@ fn resolve_excluded_paths(cx: &Context) -> Vec { for _ in WalkDir::new(excluded).into_iter().filter_entry(|e| { let p = e.path(); if !p.is_dir() { - if p.extension().map_or(false, |e| e == "rs") { + if p.extension().is_some_and(|e| e == "rs") { let p = p.strip_prefix(&cx.ws.metadata.workspace_root).unwrap_or(p); excluded_path.push(p.to_owned().try_into().unwrap()); }