@@ -130,7 +130,7 @@ use {
130130 future:: Future ,
131131 hash:: { Hash , Hasher } ,
132132 iter:: FusedIterator ,
133- mem,
133+ mem:: ManuallyDrop ,
134134 ops:: { Deref , DerefMut } ,
135135 pin:: Pin ,
136136 task:: { Context , Poll } ,
@@ -280,9 +280,8 @@ impl<'a, T: ?Sized> Box<'a, T> {
280280 /// ```
281281 #[ inline]
282282 pub fn into_raw ( b : Box < ' a , T > ) -> * mut T {
283- let ptr = b. 0 as * mut T ;
284- mem:: forget ( b) ;
285- ptr
283+ let mut b = ManuallyDrop :: new ( b) ;
284+ b. deref_mut ( ) . 0 as * mut T
286285 }
287286
288287 /// Consumes and leaks the `Box`, returning a mutable reference,
@@ -662,20 +661,20 @@ impl<'a, F: ?Sized + Future + Unpin> Future for Box<'a, F> {
662661
663662/// This impl replaces unsize coercion.
664663impl < ' a , T , const N : usize > From < Box < ' a , [ T ; N ] > > for Box < ' a , [ T ] > {
665- fn from ( mut arr : Box < ' a , [ T ; N ] > ) -> Box < ' a , [ T ] > {
664+ fn from ( arr : Box < ' a , [ T ; N ] > ) -> Box < ' a , [ T ] > {
665+ let mut arr = ManuallyDrop :: new ( arr) ;
666666 let ptr = core:: ptr:: slice_from_raw_parts_mut ( arr. as_mut_ptr ( ) , N ) ;
667- mem:: forget ( arr) ;
668667 unsafe { Box :: from_raw ( ptr) }
669668 }
670669}
671670
672671/// This impl replaces unsize coercion.
673672impl < ' a , T , const N : usize > TryFrom < Box < ' a , [ T ] > > for Box < ' a , [ T ; N ] > {
674673 type Error = Box < ' a , [ T ] > ;
675- fn try_from ( mut slice : Box < ' a , [ T ] > ) -> Result < Box < ' a , [ T ; N ] > , Box < ' a , [ T ] > > {
674+ fn try_from ( slice : Box < ' a , [ T ] > ) -> Result < Box < ' a , [ T ; N ] > , Box < ' a , [ T ] > > {
676675 if slice. len ( ) == N {
676+ let mut slice = ManuallyDrop :: new ( slice) ;
677677 let ptr = slice. as_mut_ptr ( ) as * mut [ T ; N ] ;
678- mem:: forget ( slice) ;
679678 Ok ( unsafe { Box :: from_raw ( ptr) } )
680679 } else {
681680 Err ( slice)
0 commit comments