From b2d7ef9583bdcd739275e65365cdcd5100701bc3 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 27 Apr 2026 17:44:40 -0500 Subject: [PATCH] Better clarify `MINIMUM_SESSIONS_TO_FETCH` asserts --- crates/handlers/src/compat/login.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/handlers/src/compat/login.rs b/crates/handlers/src/compat/login.rs index eef42d41c..79ba7541a 100644 --- a/crates/handlers/src/compat/login.rs +++ b/crates/handlers/src/compat/login.rs @@ -642,12 +642,18 @@ const MINIMUM_SESSIONS_TO_FETCH: usize = { let min_sessions = INACTIVE_SESSION_THRESHOLD.num_days() * 24; // Ideally, we'd use `usize::try_from(min_sessions)` but that doesn't work in const // contexts. - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] { + // Sanity check that `clippy::cast_sign_loss` doesn't apply assert!( min_sessions >= 0, - "`INACTIVE_SESSION_THRESHOLD` must be non-negative (we want to convert to a usize)" + "`MINIMUM_SESSIONS_TO_FETCH` must be non-negative (we want to convert to a usize)" ); + // For `clippy::cast_possible_truncation`, we're going to assume that someone + // doesn't specify some value bigger than can fit in the `usize`. On a 16-bit + // platform, that would be 65,535 days. + + // Based on the above asserts, we can assume that that the cast is safe min_sessions as usize } };