From d7cb7da07661ce42c36ba2dd4bc0edcad11a7e81 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 27 Sep 2021 18:49:32 +0300 Subject: 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 --- openpgp/src/cert/builder.rs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'openpgp/src/cert/builder.rs') 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)?; -- cgit v1.2.3