We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 72ad968 + 74a97e8 commit 0f7388cCopy full SHA for 0f7388c
core/src/ptr/non_null.rs
@@ -2,6 +2,7 @@ use crate::cmp::Ordering;
2
use crate::convert::From;
3
use crate::fmt;
4
use crate::hash;
5
+use crate::intrinsics::assert_unsafe_precondition;
6
use crate::marker::Unsize;
7
use crate::mem::{self, MaybeUninit};
8
use crate::num::NonZeroUsize;
@@ -195,7 +196,10 @@ impl<T: ?Sized> NonNull<T> {
195
196
#[inline]
197
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
198
// SAFETY: the caller must guarantee that `ptr` is non-null.
- unsafe { NonNull { pointer: ptr as _ } }
199
+ unsafe {
200
+ assert_unsafe_precondition!([T: ?Sized](ptr: *mut T) => !ptr.is_null());
201
+ NonNull { pointer: ptr as _ }
202
+ }
203
}
204
205
/// Creates a new `NonNull` if `ptr` is non-null.
0 commit comments