mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Rollup merge of #103329 - saethlin:nonnull-precondition, r=thomcc
Add a forgotten check for NonNull::new_unchecked's precondition Looks like I forgot this function a while ago in https://github.com/rust-lang/rust/pull/92686 r? ```@thomcc```
This commit is contained in:
commit
3f49f9506f
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user