From 9f5a5d0adac3c259ae081384da604977bb68a486 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 14 Jan 2024 23:34:07 +0800 Subject: [PATCH] rustfmt vs rustc linter: FIGHT rustfmt shortened some blocks to be one-liners. the blocks ensure the contents have Drop called on them. the linter hates the braces, saying they are unused. Perhaps, in fact, the contents don't need Drop called on them exactly at that time because there isn't a conflicting statement elsewhere in the block that uses it. It *might* be right. But then, later on, when you write some code that assumes that implicit Drop happened, guess what. You'll spend hours scratching your head as to what went wrong. I just stuck a comment in the block to keep rustfmt from thinking it should format that block. --- apps/vault/src/actions.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/vault/src/actions.rs b/apps/vault/src/actions.rs index aee24f9ca..9a77b0eca 100644 --- a/apps/vault/src/actions.rs +++ b/apps/vault/src/actions.rs @@ -134,7 +134,11 @@ impl<'a> ActionManager<'a> { // the drawing thread promises not to change the mode of the UI when this is true // in return, we get to grab a copy of the operating mode variable, which allows the // drawing thread to proceed as it relies also on reading this shared state to draw its UI. - self.mode_cache = { (*self.mode.lock().unwrap()).clone() }; + self.mode_cache = { + // Wrap this in a block so the lock Drops. This comment keeps rustfmt from shortening the block + // and then clippy from complaining about unused braces. + (*self.mode.lock().unwrap()).clone() + }; self.action_active.store(true, Ordering::SeqCst); #[cfg(feature = "ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); // allow calling menu to close @@ -1050,7 +1054,11 @@ impl<'a> ActionManager<'a> { } pub(crate) fn is_db_empty(&mut self) -> bool { - self.mode_cache = { (*self.mode.lock().unwrap()).clone() }; + self.mode_cache = { + // Wrap this in a block so the lock Drops. This comment keeps rustfmt from shortening the block + // and then clippy from complaining about unused braces. + (*self.mode.lock().unwrap()).clone() + }; self.item_lists.lock().unwrap().is_db_empty(self.mode_cache) } @@ -1068,7 +1076,11 @@ impl<'a> ActionManager<'a> { #[cfg(feature = "vaultperf")] self.perfentry(&self.pm, PERFMETA_STARTBLOCK, 0, std::line!()); - self.mode_cache = { (*self.mode.lock().unwrap()).clone() }; + self.mode_cache = { + // Wrap this in a block so the lock Drops. This comment keeps rustfmt from shortening the block + // and then clippy from complaining about unused braces. + (*self.mode.lock().unwrap()).clone() + }; log::debug!("heap usage A: {}", heap_usage()); match self.mode_cache { VaultMode::Password => {