From 34a8133d9f2f579865a01334e28216288eacc2f5 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 28 Jun 2024 12:50:39 -0400 Subject: [PATCH] tree-wide: Convert to let-else syntax Convert to [let else](https://doc.rust-lang.org/rust-by-example/flow_control/let_else.html) where possible. I've been coding Rust long before it was stable, and my muscle memory has the expanded form. But the short form is nicer. Signed-off-by: Colin Walters --- lib/src/blockdev.rs | 4 +--- lib/src/containerenv.rs | 4 +--- lib/src/deploy.rs | 4 +--- lib/src/install.rs | 4 +--- lib/src/kargs.rs | 8 ++------ xtask/src/xtask.rs | 8 ++------ 6 files changed, 8 insertions(+), 24 deletions(-) diff --git a/lib/src/blockdev.rs b/lib/src/blockdev.rs index 195a1d1d7..7f737f151 100644 --- a/lib/src/blockdev.rs +++ b/lib/src/blockdev.rs @@ -122,9 +122,7 @@ impl LoopbackDevice { // Shared backend for our `close` and `drop` implementations. fn impl_close(&mut self) -> Result<()> { // SAFETY: This is the only place we take the option - let dev = if let Some(dev) = self.dev.take() { - dev - } else { + let Some(dev) = self.dev.take() else { tracing::trace!("loopback device already deallocated"); return Ok(()); }; diff --git a/lib/src/containerenv.rs b/lib/src/containerenv.rs index 71e0e0899..491d1f966 100644 --- a/lib/src/containerenv.rs +++ b/lib/src/containerenv.rs @@ -35,9 +35,7 @@ pub(crate) fn get_container_execution_info(rootfs: &Dir) -> Result Result { continue; } let name = ent.file_name(); - let name = if let Some(name) = name.to_str() { - name - } else { + let Some(name) = name.to_str() else { continue; }; dirs.push((name.to_owned(), ent.metadata()?.mtime())); diff --git a/lib/src/install.rs b/lib/src/install.rs index 4d995f692..b9d6a653e 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -1570,9 +1570,7 @@ pub(crate) async fn install_to_filesystem( loop { tracing::debug!("Finding parents for {dev}"); let mut parents = crate::blockdev::find_parent_devices(&dev)?.into_iter(); - let parent = if let Some(f) = parents.next() { - f - } else { + let Some(parent) = parents.next() else { break; }; if let Some(next) = parents.next() { diff --git a/lib/src/kargs.rs b/lib/src/kargs.rs index d06be2562..4c84706b9 100644 --- a/lib/src/kargs.rs +++ b/lib/src/kargs.rs @@ -35,9 +35,7 @@ impl Config { /// a combined list. pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result> { // If the directory doesn't exist, that's OK. - let d = if let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? { - d - } else { + let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? else { return Ok(Default::default()); }; let mut ret = Vec::new(); @@ -74,9 +72,7 @@ fn get_kargs_from_ostree( while let Some(fetched_info) = fetched_iter.next_file(cancellable)? { // only read and parse the file if it is a toml file let name = fetched_info.name(); - let name = if let Some(name) = name.to_str() { - name - } else { + let Some(name) = name.to_str() else { continue; }; if !Config::filename_matches(name) { diff --git a/xtask/src/xtask.rs b/xtask/src/xtask.rs index 843f264cd..985724c52 100644 --- a/xtask/src/xtask.rs +++ b/xtask/src/xtask.rs @@ -95,9 +95,7 @@ fn manpages(sh: &Shell) -> Result<()> { for ent in std::fs::read_dir(extradir)? { let ent = ent?; let srcpath = ent.path(); - let extension = if let Some(extension) = srcpath.extension() { - extension - } else { + let Some(extension) = srcpath.extension() else { continue; }; if extension != "md" { @@ -302,9 +300,7 @@ fn impl_srpm(sh: &Shell) -> Result { for e in std::fs::read_dir(td)? { let e = e?; let n = e.file_name(); - let n = if let Some(n) = n.to_str() { - n - } else { + let Some(n) = n.to_str() else { continue; }; if n.ends_with(".src.rpm") {