Commit 74a97e8 1 parent b66c84a commit 74a97e8 Copy full SHA for 74a97e8
File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::cmp::Ordering;
2
2
use crate :: convert:: From ;
3
3
use crate :: fmt;
4
4
use crate :: hash;
5
+ use crate :: intrinsics:: assert_unsafe_precondition;
5
6
use crate :: marker:: Unsize ;
6
7
use crate :: mem:: { self , MaybeUninit } ;
7
8
use crate :: num:: NonZeroUsize ;
@@ -195,7 +196,10 @@ impl<T: ?Sized> NonNull<T> {
195
196
#[ inline]
196
197
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
197
198
// SAFETY: the caller must guarantee that `ptr` is non-null.
198
- 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
+ }
199
203
}
200
204
201
205
/// Creates a new `NonNull` if `ptr` is non-null.
You can’t perform that action at this time.
0 commit comments