diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-09-27 18:49:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2021-09-30 08:31:12 +0300 |
commit | d7cb7da07661ce42c36ba2dd4bc0edcad11a7e81 (patch) | |
tree | 830a8bcde3f3b6537af99976d5e8385bf4a42e83 /openpgp/src/cert/builder.rs | |
parent | 28f1cef827fc738f48b723974f4fe4229ad6dc67 (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 'openpgp/src/cert/builder.rs')
-rw-r--r-- | openpgp/src/cert/builder.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 0ceb0579..235f2cd9 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -1336,17 +1336,15 @@ impl CertBuilder<'_> { a.remove_all(SubpacketTag::PrimaryUserID); Ok(a) })?; + } else if have_primary_user_thing { + // Check if this is the first explicitly selected + // user thing. + emitted_primary_user_thing |= + sig.primary_userid().unwrap_or(false); } else { - if have_primary_user_thing { - // Check if this is the first explicitly selected - // user thing. - emitted_primary_user_thing |= - sig.primary_userid().unwrap_or(false); - } else { - // Implicitly mark the first as primary. - sig = sig.set_primary_userid(true)?; - emitted_primary_user_thing = true; - } + // Implicitly mark the first as primary. + sig = sig.set_primary_userid(true)?; + emitted_primary_user_thing = true; } let signature = uid.bind(&mut signer, &cert, sig)?; @@ -1368,17 +1366,15 @@ impl CertBuilder<'_> { a.remove_all(SubpacketTag::PrimaryUserID); Ok(a) })?; + } else if have_primary_user_thing { + // Check if this is the first explicitly selected + // user thing. + emitted_primary_user_thing |= + sig.primary_userid().unwrap_or(false); } else { - if have_primary_user_thing { - // Check if this is the first explicitly selected - // user thing. - emitted_primary_user_thing |= - sig.primary_userid().unwrap_or(false); - } else { - // Implicitly mark the first as primary. - sig = sig.set_primary_userid(true)?; - emitted_primary_user_thing = true; - } + // Implicitly mark the first as primary. + sig = sig.set_primary_userid(true)?; + emitted_primary_user_thing = true; } let signature = ua.bind(&mut signer, &cert, sig)?; |