From ea9f6e8f9761576ce53f8defee1891b0c82f60d9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 5 Aug 2024 07:43:58 +1000 Subject: [PATCH] Cast after calling min In an effort to reduce the cognitive load of reading code we are removing casts unless they are useful or obvious. Move the cast onto the call to `min` and comment it for good measure. This allows us to call infallible `from` for conversion when needed. Refactor only, no logic changes. --- bitcoin/src/bip158.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs index d737f22fa..d5b61a549 100644 --- a/bitcoin/src/bip158.rs +++ b/bitcoin/src/bip158.rs @@ -435,9 +435,9 @@ impl GcsFilter { let mut wrote = 0; let mut q = n >> self.p; while q > 0 { - let nbits = cmp::min(q, 64); - wrote += writer.write(!0u64, nbits as u8)?; - q -= nbits; + let nbits = cmp::min(q, 64) as u8; // cast ok, 64 fits into a `u8` + wrote += writer.write(!0u64, nbits)?; + q -= u64::from(nbits); } wrote += writer.write(0, 1)?; wrote += writer.write(n, self.p)?;