Skip to content

Commit

Permalink
Add extra assertions to NaiveDate::from_yof
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 15, 2024
1 parent 236b7ad commit d91b7d4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/naive/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,10 +1437,14 @@ impl NaiveDate {
/// Create a new `NaiveDate` from a raw year-ordinal-flags `i32`.
///
/// In a valid value an ordinal is never `0`, and neither are the year flags. This method
/// doesn't do any validation.
/// doesn't do any validation in release builds.
#[inline]
const fn from_yof(yof: i32) -> NaiveDate {
debug_assert!(yof != 0);
// The following are the invariants our ordinal and flags should uphold for a valid
// `NaiveDate`.
debug_assert!(((yof & OL_MASK) >> 3) > 1);
debug_assert!(((yof & OL_MASK) >> 3) <= MAX_OL);
debug_assert!((yof & 0b111) != 000);
NaiveDate { yof: unsafe { NonZeroI32::new_unchecked(yof) } }
}

Expand Down

0 comments on commit d91b7d4

Please sign in to comment.