[pbs-devel] [PATCH proxmox 04/19] tfa: don't use block in conditions
Shannon Sterz
s.sterz at proxmox.com
Thu Mar 6 13:43:34 CET 2025
this fixes a clippy style lint that does not allow blocks in
conditionals. moving the block out and the result into a temporary
variable should make this more legible [1].
[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
proxmox-tfa/src/api/methods.rs | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/proxmox-tfa/src/api/methods.rs b/proxmox-tfa/src/api/methods.rs
index 03dd8b4b..3c6dac40 100644
--- a/proxmox-tfa/src/api/methods.rs
+++ b/proxmox-tfa/src/api/methods.rs
@@ -103,12 +103,14 @@ pub fn get_tfa_entry(config: &TfaConfig, userid: &str, id: &str) -> Option<Typed
None => return None,
};
- Some(
- match {
+ Some({
+ let res = {
// scope to prevent the temporary iter from borrowing across the whole match
let entry = tfa_id_iter(user_data).find(|(_ty, _index, entry_id)| id == *entry_id);
entry.map(|(ty, index, _)| (ty, index))
- } {
+ };
+
+ match res {
Some((TfaType::Recovery, _)) => match &user_data.recovery {
Some(recovery) => TypedTfaInfo {
ty: TfaType::Recovery,
@@ -133,8 +135,8 @@ pub fn get_tfa_entry(config: &TfaConfig, userid: &str, id: &str) -> Option<Typed
info: user_data.yubico.get(index).unwrap().info.clone(),
},
None => return None,
- },
- )
+ }
+ })
}
pub struct EntryNotFound;
@@ -154,11 +156,13 @@ pub struct EntryNotFound;
pub fn delete_tfa(config: &mut TfaConfig, userid: &str, id: &str) -> Result<bool, EntryNotFound> {
let user_data = config.users.get_mut(userid).ok_or(EntryNotFound)?;
- match {
+ let res = {
// scope to prevent the temporary iter from borrowing across the whole match
let entry = tfa_id_iter(user_data).find(|(_, _, entry_id)| id == *entry_id);
entry.map(|(ty, index, _)| (ty, index))
- } {
+ };
+
+ match res {
Some((TfaType::Recovery, _)) => user_data.recovery = None,
Some((TfaType::Totp, index)) => drop(user_data.totp.remove(index)),
Some((TfaType::Webauthn, index)) => drop(user_data.webauthn.remove(index)),
--
2.39.5
More information about the pbs-devel
mailing list