1
Fork 0

Make NonNull::new const

This commit is contained in:
woppopo 2022-01-23 23:04:39 +09:00
parent 16c1a9dd7c
commit 5e97fc9aa2

View file

@ -211,8 +211,9 @@ impl<T: ?Sized> NonNull<T> {
/// } /// }
/// ``` /// ```
#[stable(feature = "nonnull", since = "1.25.0")] #[stable(feature = "nonnull", since = "1.25.0")]
#[rustc_const_unstable(feature = "const_nonnull_new", issue = "93235")]
#[inline] #[inline]
pub fn new(ptr: *mut T) -> Option<Self> { pub const fn new(ptr: *mut T) -> Option<Self> {
if !ptr.is_null() { if !ptr.is_null() {
// SAFETY: The pointer is already checked and is not null // SAFETY: The pointer is already checked and is not null
Some(unsafe { Self::new_unchecked(ptr) }) Some(unsafe { Self::new_unchecked(ptr) })