@@ -122,7 +122,8 @@ impl<T: Sized> NonNull<T> {
122
122
#[ inline]
123
123
#[ must_use]
124
124
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
125
- pub unsafe fn as_uninit_ref < ' a > ( & self ) -> & ' a MaybeUninit < T > {
125
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
126
+ pub const unsafe fn as_uninit_ref < ' a > ( & self ) -> & ' a MaybeUninit < T > {
126
127
// SAFETY: the caller must guarantee that `self` meets all the
127
128
// requirements for a reference.
128
129
unsafe { & * self . cast ( ) . as_ptr ( ) }
@@ -155,7 +156,8 @@ impl<T: Sized> NonNull<T> {
155
156
#[ inline]
156
157
#[ must_use]
157
158
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
158
- pub unsafe fn as_uninit_mut < ' a > ( & mut self ) -> & ' a mut MaybeUninit < T > {
159
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
160
+ pub const unsafe fn as_uninit_mut < ' a > ( & mut self ) -> & ' a mut MaybeUninit < T > {
159
161
// SAFETY: the caller must guarantee that `self` meets all the
160
162
// requirements for a reference.
161
163
unsafe { & mut * self . cast ( ) . as_ptr ( ) }
@@ -316,9 +318,10 @@ impl<T: ?Sized> NonNull<T> {
316
318
///
317
319
/// [the module documentation]: crate::ptr#safety
318
320
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
321
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
319
322
#[ must_use]
320
323
#[ inline]
321
- pub unsafe fn as_ref < ' a > ( & self ) -> & ' a T {
324
+ pub const unsafe fn as_ref < ' a > ( & self ) -> & ' a T {
322
325
// SAFETY: the caller must guarantee that `self` meets all the
323
326
// requirements for a reference.
324
327
unsafe { & * self . as_ptr ( ) }
@@ -366,9 +369,10 @@ impl<T: ?Sized> NonNull<T> {
366
369
///
367
370
/// [the module documentation]: crate::ptr#safety
368
371
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
372
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
369
373
#[ must_use]
370
374
#[ inline]
371
- pub unsafe fn as_mut < ' a > ( & mut self ) -> & ' a mut T {
375
+ pub const unsafe fn as_mut < ' a > ( & mut self ) -> & ' a mut T {
372
376
// SAFETY: the caller must guarantee that `self` meets all the
373
377
// requirements for a mutable reference.
374
378
unsafe { & mut * self . as_ptr ( ) }
@@ -534,7 +538,8 @@ impl<T> NonNull<[T]> {
534
538
#[ inline]
535
539
#[ must_use]
536
540
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
537
- pub unsafe fn as_uninit_slice < ' a > ( & self ) -> & ' a [ MaybeUninit < T > ] {
541
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
542
+ pub const unsafe fn as_uninit_slice < ' a > ( & self ) -> & ' a [ MaybeUninit < T > ] {
538
543
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
539
544
unsafe { slice:: from_raw_parts ( self . cast ( ) . as_ptr ( ) , self . len ( ) ) }
540
545
}
@@ -596,7 +601,8 @@ impl<T> NonNull<[T]> {
596
601
#[ inline]
597
602
#[ must_use]
598
603
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
599
- pub unsafe fn as_uninit_slice_mut < ' a > ( & self ) -> & ' a mut [ MaybeUninit < T > ] {
604
+ #[ rustc_const_unstable( feature = "const_ptr_as_ref" , issue = "91822" ) ]
605
+ pub const unsafe fn as_uninit_slice_mut < ' a > ( & self ) -> & ' a mut [ MaybeUninit < T > ] {
600
606
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
601
607
unsafe { slice:: from_raw_parts_mut ( self . cast ( ) . as_ptr ( ) , self . len ( ) ) }
602
608
}
0 commit comments