about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2025-01-10 18:52:22 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2025-01-10 18:52:22 -0800
commitebd6d3f225492e2d89950d38415b54060dc5ab7c (patch)
tree73ab17c416343d795779e97668f6b3955d3ad9be
parent6f2a78345ee7f55c5ce33fd7b9804c665c646dd2 (diff)
downloadrust-ebd6d3f225492e2d89950d38415b54060dc5ab7c.tar.gz
rust-ebd6d3f225492e2d89950d38415b54060dc5ab7c.zip
Improve the safety documentation on new_unchecked
-rw-r--r--library/core/src/num/niche_types.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/core/src/num/niche_types.rs b/library/core/src/num/niche_types.rs
index e4caf8a104c..096713c318f 100644
--- a/library/core/src/num/niche_types.rs
+++ b/library/core/src/num/niche_types.rs
@@ -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) }
             }