@@ -119,6 +119,7 @@ impl<T: Sized> NonNull<T> {
119119 ///
120120 /// [the module documentation]: crate::ptr#safety
121121 #[ inline]
122+ #[ must_use]
122123 #[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
123124 pub unsafe fn as_uninit_ref < ' a > ( & self ) -> & ' a MaybeUninit < T > {
124125 // SAFETY: the caller must guarantee that `self` meets all the
@@ -151,6 +152,7 @@ impl<T: Sized> NonNull<T> {
151152 ///
152153 /// [the module documentation]: crate::ptr#safety
153154 #[ inline]
155+ #[ must_use]
154156 #[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
155157 pub unsafe fn as_uninit_mut < ' a > ( & mut self ) -> & ' a mut MaybeUninit < T > {
156158 // SAFETY: the caller must guarantee that `self` meets all the
@@ -264,6 +266,7 @@ impl<T: ?Sized> NonNull<T> {
264266 /// ```
265267 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
266268 #[ rustc_const_stable( feature = "const_nonnull_as_ptr" , since = "1.32.0" ) ]
269+ #[ must_use]
267270 #[ inline]
268271 pub const fn as_ptr ( self ) -> * mut T {
269272 self . pointer as * mut T
@@ -310,6 +313,7 @@ impl<T: ?Sized> NonNull<T> {
310313 ///
311314 /// [the module documentation]: crate::ptr#safety
312315 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
316+ #[ must_use]
313317 #[ inline]
314318 pub unsafe fn as_ref < ' a > ( & self ) -> & ' a T {
315319 // SAFETY: the caller must guarantee that `self` meets all the
@@ -359,6 +363,7 @@ impl<T: ?Sized> NonNull<T> {
359363 ///
360364 /// [the module documentation]: crate::ptr#safety
361365 #[ stable( feature = "nonnull" , since = "1.25.0" ) ]
366+ #[ must_use]
362367 #[ inline]
363368 pub unsafe fn as_mut < ' a > ( & mut self ) -> & ' a mut T {
364369 // SAFETY: the caller must guarantee that `self` meets all the
@@ -455,6 +460,7 @@ impl<T> NonNull<[T]> {
455460 /// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
456461 /// ```
457462 #[ inline]
463+ #[ must_use]
458464 #[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
459465 #[ rustc_const_unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
460466 pub const fn as_non_null_ptr ( self ) -> NonNull < T > {
@@ -474,6 +480,7 @@ impl<T> NonNull<[T]> {
474480 /// assert_eq!(slice.as_mut_ptr(), 1 as *mut i8);
475481 /// ```
476482 #[ inline]
483+ #[ must_use]
477484 #[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
478485 #[ rustc_const_unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
479486 pub const fn as_mut_ptr ( self ) -> * mut T {
@@ -518,6 +525,7 @@ impl<T> NonNull<[T]> {
518525 ///
519526 /// [valid]: crate::ptr#safety
520527 #[ inline]
528+ #[ must_use]
521529 #[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
522530 pub unsafe fn as_uninit_slice < ' a > ( & self ) -> & ' a [ MaybeUninit < T > ] {
523531 // SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
@@ -579,6 +587,7 @@ impl<T> NonNull<[T]> {
579587 /// # Ok::<_, std::alloc::AllocError>(())
580588 /// ```
581589 #[ inline]
590+ #[ must_use]
582591 #[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
583592 pub unsafe fn as_uninit_slice_mut < ' a > ( & self ) -> & ' a mut [ MaybeUninit < T > ] {
584593 // SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
0 commit comments