Skip to content

Commit 0cf5b9e

Browse files
authored
Merge pull request #650 from cgwalters/let-else
tree-wide: Convert to let-else syntax
2 parents 40ad730 + 34a8133 commit 0cf5b9e

File tree

6 files changed

+8
-24
lines changed

6 files changed

+8
-24
lines changed

lib/src/blockdev.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ impl LoopbackDevice {
122122
// Shared backend for our `close` and `drop` implementations.
123123
fn impl_close(&mut self) -> Result<()> {
124124
// SAFETY: This is the only place we take the option
125-
let dev = if let Some(dev) = self.dev.take() {
126-
dev
127-
} else {
125+
let Some(dev) = self.dev.take() else {
128126
tracing::trace!("loopback device already deallocated");
129127
return Ok(());
130128
};

lib/src/containerenv.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ pub(crate) fn get_container_execution_info(rootfs: &Dir) -> Result<ContainerExec
3535
for line in f.lines() {
3636
let line = line?;
3737
let line = line.trim();
38-
let (k, v) = if let Some(v) = line.split_once('=') {
39-
v
40-
} else {
38+
let Some((k, v)) = line.split_once('=') else {
4139
continue;
4240
};
4341
// Assuming there's no quotes here

lib/src/deploy.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result<String> {
401401
continue;
402402
}
403403
let name = ent.file_name();
404-
let name = if let Some(name) = name.to_str() {
405-
name
406-
} else {
404+
let Some(name) = name.to_str() else {
407405
continue;
408406
};
409407
dirs.push((name.to_owned(), ent.metadata()?.mtime()));

lib/src/install.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,9 +1570,7 @@ pub(crate) async fn install_to_filesystem(
15701570
loop {
15711571
tracing::debug!("Finding parents for {dev}");
15721572
let mut parents = crate::blockdev::find_parent_devices(&dev)?.into_iter();
1573-
let parent = if let Some(f) = parents.next() {
1574-
f
1575-
} else {
1573+
let Some(parent) = parents.next() else {
15761574
break;
15771575
};
15781576
if let Some(next) = parents.next() {

lib/src/kargs.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ impl Config {
3535
/// a combined list.
3636
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
3737
// If the directory doesn't exist, that's OK.
38-
let d = if let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? {
39-
d
40-
} else {
38+
let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? else {
4139
return Ok(Default::default());
4240
};
4341
let mut ret = Vec::new();
@@ -74,9 +72,7 @@ fn get_kargs_from_ostree(
7472
while let Some(fetched_info) = fetched_iter.next_file(cancellable)? {
7573
// only read and parse the file if it is a toml file
7674
let name = fetched_info.name();
77-
let name = if let Some(name) = name.to_str() {
78-
name
79-
} else {
75+
let Some(name) = name.to_str() else {
8076
continue;
8177
};
8278
if !Config::filename_matches(name) {

xtask/src/xtask.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ fn manpages(sh: &Shell) -> Result<()> {
9595
for ent in std::fs::read_dir(extradir)? {
9696
let ent = ent?;
9797
let srcpath = ent.path();
98-
let extension = if let Some(extension) = srcpath.extension() {
99-
extension
100-
} else {
98+
let Some(extension) = srcpath.extension() else {
10199
continue;
102100
};
103101
if extension != "md" {
@@ -302,9 +300,7 @@ fn impl_srpm(sh: &Shell) -> Result<Utf8PathBuf> {
302300
for e in std::fs::read_dir(td)? {
303301
let e = e?;
304302
let n = e.file_name();
305-
let n = if let Some(n) = n.to_str() {
306-
n
307-
} else {
303+
let Some(n) = n.to_str() else {
308304
continue;
309305
};
310306
if n.ends_with(".src.rpm") {

0 commit comments

Comments
 (0)