Skip to content

Commit

Permalink
Fix clippy::unnecessary_map_or warning
Browse files Browse the repository at this point in the history
```
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
```
  • Loading branch information
taiki-e committed Nov 17, 2024
1 parent 232d762 commit 256acb4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_ok_and(|s| s.contains("doctest-in-workspace"));
}

let target_dir =
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_ok_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.
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ fn object_files(cx: &Context) -> Result<Vec<OsString>> {
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;
Expand Down Expand Up @@ -1310,7 +1310,7 @@ fn resolve_excluded_paths(cx: &Context) -> Vec<Utf8PathBuf> {
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());
}
Expand Down

0 comments on commit 256acb4

Please sign in to comment.