diff options
| author | Ben Kimock <kimockb@gmail.com> | 2022-10-20 20:40:35 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2022-10-20 20:40:35 -0400 |
| commit | 9b6791078a580acdd05246f00f900cbc079bb95e (patch) | |
| tree | 505a3aec81b1b911aaea01244a7a8e9feba712ef /library/core | |
| parent | 5ffa67d7309047ff47b9c624ba4061fb8c004c31 (diff) | |
| download | rust-9b6791078a580acdd05246f00f900cbc079bb95e.tar.gz rust-9b6791078a580acdd05246f00f900cbc079bb95e.zip | |
Add a missing precondition check
Diffstat (limited to 'library/core')
| -rw-r--r-- | library/core/src/ptr/non_null.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index f3ef094cbcc..7264d57ba6a 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -2,6 +2,7 @@ use crate::cmp::Ordering; use crate::convert::From; use crate::fmt; use crate::hash; +use crate::intrinsics::assert_unsafe_precondition; use crate::marker::Unsize; use crate::mem::{self, MaybeUninit}; use crate::num::NonZeroUsize; @@ -195,7 +196,10 @@ impl<T: ?Sized> NonNull<T> { #[inline] pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { // SAFETY: the caller must guarantee that `ptr` is non-null. - unsafe { NonNull { pointer: ptr as _ } } + unsafe { + assert_unsafe_precondition!([T: ?Sized](ptr: *mut T) => !ptr.is_null()); + NonNull { pointer: ptr as _ } + } } /// Creates a new `NonNull` if `ptr` is non-null. |
