@@ -187,6 +187,7 @@ impl<T> Box<T> {
187
187
#[ cfg( not( no_global_oom_handling) ) ]
188
188
#[ inline( always) ]
189
189
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
190
+ #[ must_use]
190
191
pub fn new ( x : T ) -> Self {
191
192
box x
192
193
}
@@ -211,6 +212,7 @@ impl<T> Box<T> {
211
212
/// ```
212
213
#[ cfg( not( no_global_oom_handling) ) ]
213
214
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
215
+ #[ must_use]
214
216
#[ inline]
215
217
pub fn new_uninit ( ) -> Box < mem:: MaybeUninit < T > > {
216
218
Self :: new_uninit_in ( Global )
@@ -237,6 +239,7 @@ impl<T> Box<T> {
237
239
#[ cfg( not( no_global_oom_handling) ) ]
238
240
#[ inline]
239
241
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
242
+ #[ must_use]
240
243
pub fn new_zeroed ( ) -> Box < mem:: MaybeUninit < T > > {
241
244
Self :: new_zeroed_in ( Global )
242
245
}
@@ -245,6 +248,7 @@ impl<T> Box<T> {
245
248
/// `x` will be pinned in memory and unable to be moved.
246
249
#[ cfg( not( no_global_oom_handling) ) ]
247
250
#[ stable( feature = "pin" , since = "1.33.0" ) ]
251
+ #[ must_use]
248
252
#[ inline( always) ]
249
253
pub fn pin ( x : T ) -> Pin < Box < T > > {
250
254
( box x) . into ( )
@@ -339,6 +343,7 @@ impl<T, A: Allocator> Box<T, A> {
339
343
/// ```
340
344
#[ cfg( not( no_global_oom_handling) ) ]
341
345
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
346
+ #[ must_use]
342
347
#[ inline]
343
348
pub fn new_in ( x : T , alloc : A ) -> Self {
344
349
let mut boxed = Self :: new_uninit_in ( alloc) ;
@@ -395,6 +400,7 @@ impl<T, A: Allocator> Box<T, A> {
395
400
/// ```
396
401
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
397
402
#[ cfg( not( no_global_oom_handling) ) ]
403
+ #[ must_use]
398
404
// #[unstable(feature = "new_uninit", issue = "63291")]
399
405
pub fn new_uninit_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A > {
400
406
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
@@ -459,6 +465,7 @@ impl<T, A: Allocator> Box<T, A> {
459
465
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
460
466
#[ cfg( not( no_global_oom_handling) ) ]
461
467
// #[unstable(feature = "new_uninit", issue = "63291")]
468
+ #[ must_use]
462
469
pub fn new_zeroed_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A > {
463
470
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
464
471
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
@@ -503,6 +510,7 @@ impl<T, A: Allocator> Box<T, A> {
503
510
/// `x` will be pinned in memory and unable to be moved.
504
511
#[ cfg( not( no_global_oom_handling) ) ]
505
512
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
513
+ #[ must_use]
506
514
#[ inline( always) ]
507
515
pub fn pin_in ( x : T , alloc : A ) -> Pin < Self >
508
516
where
@@ -561,6 +569,7 @@ impl<T> Box<[T]> {
561
569
/// ```
562
570
#[ cfg( not( no_global_oom_handling) ) ]
563
571
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
572
+ #[ must_use]
564
573
pub fn new_uninit_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
565
574
unsafe { RawVec :: with_capacity ( len) . into_box ( len) }
566
575
}
@@ -585,6 +594,7 @@ impl<T> Box<[T]> {
585
594
/// [zeroed]: mem::MaybeUninit::zeroed
586
595
#[ cfg( not( no_global_oom_handling) ) ]
587
596
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
597
+ #[ must_use]
588
598
pub fn new_zeroed_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
589
599
unsafe { RawVec :: with_capacity_zeroed ( len) . into_box ( len) }
590
600
}
@@ -681,6 +691,7 @@ impl<T, A: Allocator> Box<[T], A> {
681
691
#[ cfg( not( no_global_oom_handling) ) ]
682
692
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
683
693
// #[unstable(feature = "new_uninit", issue = "63291")]
694
+ #[ must_use]
684
695
pub fn new_uninit_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A > {
685
696
unsafe { RawVec :: with_capacity_in ( len, alloc) . into_box ( len) }
686
697
}
@@ -708,6 +719,7 @@ impl<T, A: Allocator> Box<[T], A> {
708
719
#[ cfg( not( no_global_oom_handling) ) ]
709
720
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
710
721
// #[unstable(feature = "new_uninit", issue = "63291")]
722
+ #[ must_use]
711
723
pub fn new_zeroed_slice_in ( len : usize , alloc : A ) -> Box < [ mem:: MaybeUninit < T > ] , A > {
712
724
unsafe { RawVec :: with_capacity_zeroed_in ( len, alloc) . into_box ( len) }
713
725
}
0 commit comments