1
Fork 0

Improve the safety documentation on new_unchecked

This commit is contained in:
Scott McMurray 2025-01-10 18:52:22 -08:00
parent 6f2a78345e
commit ebd6d3f225

View file

@ -32,9 +32,15 @@ macro_rules! define_valid_range_type {
};
impl $name {
/// Constructs an instance of this type from the underlying integer
/// primitive without checking whether its zero.
///
/// # Safety
/// Immediate language UB if `val == 0`, as it violates the validity
/// invariant of this type.
#[inline]
pub const unsafe fn new_unchecked(val: $int) -> Self {
// SAFETY: same precondition
// SAFETY: Caller promised that `val` is non-zero.
unsafe { $name(val) }
}