From af935f84bf729934e015f1420343773f41956b07 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 18 Dec 2023 06:19:27 -0500 Subject: [PATCH] init: appease clippy ``` warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` --> init/src/main.rs:127:23 | 127 | match (|| { | _______________________^ 128 | | let entry = entry.context("read_dir(/bin) failed")?; 129 | | let path = entry.path(); 130 | | let status = std::process::Command::new(&path) ... | 139 | | } 140 | | })() { | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions = note: `#[warn(clippy::blocks_in_conditions)]` on by default ``` https://github.com/rust-lang/rust-clippy/pull/11853 landed in nightly. --- init/src/main.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/init/src/main.rs b/init/src/main.rs index 89253de7..ddb46e64 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -123,25 +123,24 @@ fn run() -> anyhow::Result<()> { // Iterate files in /bin. let read_dir = std::fs::read_dir("/bin").context("read_dir(/bin) failed")?; let errors = read_dir - .filter_map(|entry| { - match (|| { - let entry = entry.context("read_dir(/bin) failed")?; - let path = entry.path(); - let status = std::process::Command::new(&path) - .args(&args) - .status() - .with_context(|| format!("failed to execute {}", path.display()))?; + .map(|entry| { + let entry = entry.context("read_dir(/bin) failed")?; + let path = entry.path(); + let status = std::process::Command::new(&path) + .args(&args) + .status() + .with_context(|| format!("failed to execute {}", path.display()))?; - if status.code() == Some(0) { - Ok(()) - } else { - Err(anyhow::anyhow!("{} failed: {status:?}", path.display())) - } - })() { - Ok(()) => None, - Err(err) => Some(err), + if status.code() == Some(0) { + Ok(()) + } else { + Err(anyhow::anyhow!("{} failed: {status:?}", path.display())) } }) + .filter_map(|result| match result { + Ok(()) => None, + Err(err) => Some(err), + }) .collect::>(); if errors.is_empty() { Ok(())