Skip to content

Commit 36f3dfc

Browse files
scottmcmgitbot
authored and
gitbot
committed
Improve the safety documentation on new_unchecked
1 parent 5b8ac3d commit 36f3dfc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/src/num/niche_types.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ macro_rules! define_valid_range_type {
3232
};
3333

3434
impl $name {
35+
/// Constructs an instance of this type from the underlying integer
36+
/// primitive without checking whether its zero.
37+
///
38+
/// # Safety
39+
/// Immediate language UB if `val == 0`, as it violates the validity
40+
/// invariant of this type.
3541
#[inline]
3642
pub const unsafe fn new_unchecked(val: $int) -> Self {
37-
// SAFETY: same precondition
43+
// SAFETY: Caller promised that `val` is non-zero.
3844
unsafe { $name(val) }
3945
}
4046

0 commit comments

Comments
 (0)