Skip to content

Conversation

abr-egn
Copy link
Contributor

@abr-egn abr-egn commented Sep 29, 2025

RUST-2127

This enables the clippy::cast_sign_loss lint and fixes all the locations it flagged. These fell into four fuzzy categories:

  • surrounding checks ensure it's infallible, but the Rust compiler can't prove it: these are now try_into().unwrap() so if the checks miss something it'll cause a panic rather than silent misbehavior;
  • conversion between float and integer: there's now an explicit function for that (that just calls lint-disabled as) to make it clear that's what's intended;
  • assuming a technically-signed value from the server is always actually unsigned: this is now checked at parse time and handled as an unsigned value everywhere beyond that;
  • test assertions, which now also use try_into().unwrap()

}

#[allow(private_bounds)]
pub(crate) fn round_clamp<T: RoundClampTarget>(input: f64) -> T {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it this way allows the type to be specified inline with the call rather than the awkwardness that Into and friends have.

}
}

pub(crate) mod option_u64_as_i64 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be just bson::serde_helpers::u64::AsI64 but we can't rely on bson 3.0 stuff :(

@abr-egn abr-egn force-pushed the RUST-2127/lint-cast-sign-loss branch from 21098b0 to 0c190d8 Compare September 29, 2025 15:13
@abr-egn abr-egn marked this pull request as ready for review September 29, 2025 17:13
@abr-egn abr-egn requested a review from a team as a code owner September 29, 2025 17:13
@abr-egn abr-egn merged commit 3f43723 into mongodb:main Oct 2, 2025
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants