mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Make NonNull::new
const
This commit is contained in:
parent
16c1a9dd7c
commit
5e97fc9aa2
@ -211,8 +211,9 @@ impl<T: ?Sized> NonNull<T> {
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_nonnull_new", issue = "93235")]
|
||||
#[inline]
|
||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
||||
pub const fn new(ptr: *mut T) -> Option<Self> {
|
||||
if !ptr.is_null() {
|
||||
// SAFETY: The pointer is already checked and is not null
|
||||
Some(unsafe { Self::new_unchecked(ptr) })
|
||||
|
Loading…
Reference in New Issue
Block a user