summaryrefslogtreecommitdiffstats
path: root/sq
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-27 18:49:32 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2021-09-30 08:31:12 +0300
commitd7cb7da07661ce42c36ba2dd4bc0edcad11a7e81 (patch)
tree830a8bcde3f3b6537af99976d5e8385bf4a42e83 /sq
parent28f1cef827fc738f48b723974f4fe4229ad6dc67 (diff)
Join nested if statements with logical and into one statement
Instead of this: if foo { if bar { ... } } do this: if foo && bar { ... } Nesting statements implies a more complicated code structure than it really is. Thus it's arguably simpler to write a combined condition by joining the two conditions with a logical and operation. Found by clippy lint collapsible_if: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
Diffstat (limited to 'sq')
-rw-r--r--sq/src/commands/dump.rs12
-rw-r--r--sq/src/sq.rs6
2 files changed, 7 insertions, 11 deletions
diff --git a/sq/src/commands/dump.rs b/sq/src/commands/dump.rs
index 3c1eda31..c2d0aa03 100644
--- a/sq/src/commands/dump.rs
+++ b/sq/src/commands/dump.rs
@@ -225,14 +225,12 @@ impl PacketDumper {
if self.root.is_none() {
assert_eq!(depth, 0);
self.root = Some(node);
+ } else if depth == 0 {
+ let root = self.root.take().unwrap();
+ self.dump_tree(output, "", &root)?;
+ self.root = Some(node);
} else {
- if depth == 0 {
- let root = self.root.take().unwrap();
- self.dump_tree(output, "", &root)?;
- self.root = Some(node);
- } else {
- self.root.as_mut().unwrap().append(depth - 1, node);
- }
+ self.root.as_mut().unwrap().append(depth - 1, node);
}
Ok(())
}
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index 37146bcc..e2ed3130 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -715,10 +715,8 @@ fn parse_iso8601(s: &str, pad_date_with: chrono::NaiveTime)
if let Ok(d) = DateTime::parse_from_str(s, *f) {
return Ok(d.into());
}
- } else {
- if let Ok(d) = chrono::NaiveDateTime::parse_from_str(s, *f) {
- return Ok(DateTime::from_utc(d, Utc));
- }
+ } else if let Ok(d) = chrono::NaiveDateTime::parse_from_str(s, *f) {
+ return Ok(DateTime::from_utc(d, Utc));
}
}
for f in &[