Better clarify MINIMUM_SESSIONS_TO_FETCH asserts

This commit is contained in:
Eric Eastwood
2026-04-27 17:44:40 -05:00
parent a06429a840
commit b2d7ef9583
+8 -2
View File
@@ -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
}
};