@@ -119,6 +119,7 @@ impl<T: Sized> NonNull<T> {
119
119
///
120
120
/// [the module documentation]: crate::ptr#safety
121
121
#[ inline]
122
+ #[ must_use]
122
123
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
123
124
pub unsafe fn as_uninit_ref < ' a > ( & self ) -> & ' a MaybeUninit < T > {
124
125
// SAFETY: the caller must guarantee that `self` meets all the
@@ -151,6 +152,7 @@ impl<T: Sized> NonNull<T> {
151
152
///
152
153
/// [the module documentation]: crate::ptr#safety
153
154
#[ inline]
155
+ #[ must_use]
154
156
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
155
157
pub unsafe fn as_uninit_mut < ' a > ( & mut self ) -> & ' a mut MaybeUninit < T > {
156
158
// SAFETY: the caller must guarantee that `self` meets all the
@@ -264,6 +266,7 @@ impl<T: ?Sized> NonNull<T> {
264
266
/// ```
265
267
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
266
268
#[ rustc_const_stable( feature = "const_nonnull_as_ptr" , since = "1.32.0" ) ]
269
+ #[ must_use]
267
270
#[ inline]
268
271
pub const fn as_ptr ( self ) -> * mut T {
269
272
self . pointer as * mut T
@@ -310,6 +313,7 @@ impl<T: ?Sized> NonNull<T> {
310
313
///
311
314
/// [the module documentation]: crate::ptr#safety
312
315
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
316
+ #[ must_use]
313
317
#[ inline]
314
318
pub unsafe fn as_ref < ' a > ( & self ) -> & ' a T {
315
319
// SAFETY: the caller must guarantee that `self` meets all the
@@ -359,6 +363,7 @@ impl<T: ?Sized> NonNull<T> {
359
363
///
360
364
/// [the module documentation]: crate::ptr#safety
361
365
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
366
+ #[ must_use]
362
367
#[ inline]
363
368
pub unsafe fn as_mut < ' a > ( & mut self ) -> & ' a mut T {
364
369
// SAFETY: the caller must guarantee that `self` meets all the
@@ -455,6 +460,7 @@ impl<T> NonNull<[T]> {
455
460
/// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
456
461
/// ```
457
462
#[ inline]
463
+ #[ must_use]
458
464
#[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
459
465
#[ rustc_const_unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
460
466
pub const fn as_non_null_ptr ( self ) -> NonNull < T > {
@@ -474,6 +480,7 @@ impl<T> NonNull<[T]> {
474
480
/// assert_eq!(slice.as_mut_ptr(), 1 as *mut i8);
475
481
/// ```
476
482
#[ inline]
483
+ #[ must_use]
477
484
#[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
478
485
#[ rustc_const_unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
479
486
pub const fn as_mut_ptr ( self ) -> * mut T {
@@ -518,6 +525,7 @@ impl<T> NonNull<[T]> {
518
525
///
519
526
/// [valid]: crate::ptr#safety
520
527
#[ inline]
528
+ #[ must_use]
521
529
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
522
530
pub unsafe fn as_uninit_slice < ' a > ( & self ) -> & ' a [ MaybeUninit < T > ] {
523
531
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
@@ -579,6 +587,7 @@ impl<T> NonNull<[T]> {
579
587
/// # Ok::<_, std::alloc::AllocError>(())
580
588
/// ```
581
589
#[ inline]
590
+ #[ must_use]
582
591
#[ unstable( feature = "ptr_as_uninit" , issue = "75402" ) ]
583
592
pub unsafe fn as_uninit_slice_mut < ' a > ( & self ) -> & ' a mut [ MaybeUninit < T > ] {
584
593
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
0 commit comments