@@ -280,13 +280,9 @@ impl<T> Box<T> {
280
280
///
281
281
/// ```
282
282
/// let mut five = Box::<u32>::new_uninit();
283
- ///
284
- /// let five = unsafe {
285
- /// // Deferred initialization:
286
- /// five.as_mut_ptr().write(5);
287
- ///
288
- /// five.assume_init()
289
- /// };
283
+ /// // Deferred initialization:
284
+ /// five.write(5);
285
+ /// let five = unsafe { five.assume_init() };
290
286
///
291
287
/// assert_eq!(*five, 5)
292
288
/// ```
@@ -367,13 +363,9 @@ impl<T> Box<T> {
367
363
/// #![feature(allocator_api)]
368
364
///
369
365
/// let mut five = Box::<u32>::try_new_uninit()?;
370
- ///
371
- /// let five = unsafe {
372
- /// // Deferred initialization:
373
- /// five.as_mut_ptr().write(5);
374
- ///
375
- /// five.assume_init()
376
- /// };
366
+ /// // Deferred initialization:
367
+ /// five.write(5);
368
+ /// let five = unsafe { five.assume_init() };
377
369
///
378
370
/// assert_eq!(*five, 5);
379
371
/// # Ok::<(), std::alloc::AllocError>(())
@@ -435,10 +427,8 @@ impl<T, A: Allocator> Box<T, A> {
435
427
A : Allocator ,
436
428
{
437
429
let mut boxed = Self :: new_uninit_in ( alloc) ;
438
- unsafe {
439
- boxed. as_mut_ptr ( ) . write ( x) ;
440
- boxed. assume_init ( )
441
- }
430
+ boxed. write ( x) ;
431
+ unsafe { boxed. assume_init ( ) }
442
432
}
443
433
444
434
/// Allocates memory in the given allocator then places `x` into it,
@@ -463,10 +453,8 @@ impl<T, A: Allocator> Box<T, A> {
463
453
A : Allocator ,
464
454
{
465
455
let mut boxed = Self :: try_new_uninit_in ( alloc) ?;
466
- unsafe {
467
- boxed. as_mut_ptr ( ) . write ( x) ;
468
- Ok ( boxed. assume_init ( ) )
469
- }
456
+ boxed. write ( x) ;
457
+ unsafe { Ok ( boxed. assume_init ( ) ) }
470
458
}
471
459
472
460
/// Constructs a new box with uninitialized contents in the provided allocator.
@@ -479,13 +467,9 @@ impl<T, A: Allocator> Box<T, A> {
479
467
/// use std::alloc::System;
480
468
///
481
469
/// let mut five = Box::<u32, _>::new_uninit_in(System);
482
- ///
483
- /// let five = unsafe {
484
- /// // Deferred initialization:
485
- /// five.as_mut_ptr().write(5);
486
- ///
487
- /// five.assume_init()
488
- /// };
470
+ /// // Deferred initialization:
471
+ /// five.write(5);
472
+ /// let five = unsafe { five.assume_init() };
489
473
///
490
474
/// assert_eq!(*five, 5)
491
475
/// ```
@@ -517,13 +501,9 @@ impl<T, A: Allocator> Box<T, A> {
517
501
/// use std::alloc::System;
518
502
///
519
503
/// let mut five = Box::<u32, _>::try_new_uninit_in(System)?;
520
- ///
521
- /// let five = unsafe {
522
- /// // Deferred initialization:
523
- /// five.as_mut_ptr().write(5);
524
- ///
525
- /// five.assume_init()
526
- /// };
504
+ /// // Deferred initialization:
505
+ /// five.write(5);
506
+ /// let five = unsafe { five.assume_init() };
527
507
///
528
508
/// assert_eq!(*five, 5);
529
509
/// # Ok::<(), std::alloc::AllocError>(())
@@ -669,15 +649,11 @@ impl<T> Box<[T]> {
669
649
///
670
650
/// ```
671
651
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
672
- ///
673
- /// let values = unsafe {
674
- /// // Deferred initialization:
675
- /// values[0].as_mut_ptr().write(1);
676
- /// values[1].as_mut_ptr().write(2);
677
- /// values[2].as_mut_ptr().write(3);
678
- ///
679
- /// values.assume_init()
680
- /// };
652
+ /// // Deferred initialization:
653
+ /// values[0].write(1);
654
+ /// values[1].write(2);
655
+ /// values[2].write(3);
656
+ /// let values = unsafe {values.assume_init() };
681
657
///
682
658
/// assert_eq!(*values, [1, 2, 3])
683
659
/// ```
@@ -722,13 +698,11 @@ impl<T> Box<[T]> {
722
698
/// #![feature(allocator_api)]
723
699
///
724
700
/// let mut values = Box::<[u32]>::try_new_uninit_slice(3)?;
725
- /// let values = unsafe {
726
- /// // Deferred initialization:
727
- /// values[0].as_mut_ptr().write(1);
728
- /// values[1].as_mut_ptr().write(2);
729
- /// values[2].as_mut_ptr().write(3);
730
- /// values.assume_init()
731
- /// };
701
+ /// // Deferred initialization:
702
+ /// values[0].write(1);
703
+ /// values[1].write(2);
704
+ /// values[2].write(3);
705
+ /// let values = unsafe { values.assume_init() };
732
706
///
733
707
/// assert_eq!(*values, [1, 2, 3]);
734
708
/// # Ok::<(), std::alloc::AllocError>(())
@@ -814,15 +788,11 @@ impl<T, A: Allocator> Box<[T], A> {
814
788
/// use std::alloc::System;
815
789
///
816
790
/// let mut values = Box::<[u32], _>::new_uninit_slice_in(3, System);
817
- ///
818
- /// let values = unsafe {
819
- /// // Deferred initialization:
820
- /// values[0].as_mut_ptr().write(1);
821
- /// values[1].as_mut_ptr().write(2);
822
- /// values[2].as_mut_ptr().write(3);
823
- ///
824
- /// values.assume_init()
825
- /// };
791
+ /// // Deferred initialization:
792
+ /// values[0].write(1);
793
+ /// values[1].write(2);
794
+ /// values[2].write(3);
795
+ /// let values = unsafe { values.assume_init() };
826
796
///
827
797
/// assert_eq!(*values, [1, 2, 3])
828
798
/// ```
@@ -873,13 +843,11 @@ impl<T, A: Allocator> Box<[T], A> {
873
843
/// use std::alloc::System;
874
844
///
875
845
/// let mut values = Box::<[u32], _>::try_new_uninit_slice_in(3, System)?;
876
- /// let values = unsafe {
877
- /// // Deferred initialization:
878
- /// values[0].as_mut_ptr().write(1);
879
- /// values[1].as_mut_ptr().write(2);
880
- /// values[2].as_mut_ptr().write(3);
881
- /// values.assume_init()
882
- /// };
846
+ /// // Deferred initialization:
847
+ /// values[0].write(1);
848
+ /// values[1].write(2);
849
+ /// values[2].write(3);
850
+ /// let values = unsafe { values.assume_init() };
883
851
///
884
852
/// assert_eq!(*values, [1, 2, 3]);
885
853
/// # Ok::<(), std::alloc::AllocError>(())
@@ -959,13 +927,9 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
959
927
///
960
928
/// ```
961
929
/// let mut five = Box::<u32>::new_uninit();
962
- ///
963
- /// let five: Box<u32> = unsafe {
964
- /// // Deferred initialization:
965
- /// five.as_mut_ptr().write(5);
966
- ///
967
- /// five.assume_init()
968
- /// };
930
+ /// // Deferred initialization:
931
+ /// five.write(5);
932
+ /// let five: Box<u32> = unsafe { five.assume_init() };
969
933
///
970
934
/// assert_eq!(*five, 5)
971
935
/// ```
@@ -1030,15 +994,11 @@ impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {
1030
994
///
1031
995
/// ```
1032
996
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
1033
- ///
1034
- /// let values = unsafe {
1035
- /// // Deferred initialization:
1036
- /// values[0].as_mut_ptr().write(1);
1037
- /// values[1].as_mut_ptr().write(2);
1038
- /// values[2].as_mut_ptr().write(3);
1039
- ///
1040
- /// values.assume_init()
1041
- /// };
997
+ /// // Deferred initialization:
998
+ /// values[0].write(1);
999
+ /// values[1].write(2);
1000
+ /// values[2].write(3);
1001
+ /// let values = unsafe { values.assume_init() };
1042
1002
///
1043
1003
/// assert_eq!(*values, [1, 2, 3])
1044
1004
/// ```
0 commit comments