@@ -520,10 +520,10 @@ impl<T> ops::Index<ops::Range<usize>> for [T] {
520520 assert ! ( index. start <= index. end) ;
521521 assert ! ( index. end <= self . len( ) ) ;
522522 unsafe {
523- transmute ( RawSlice {
524- data : self . as_ptr ( ) . offset ( index. start as isize ) ,
525- len : index. end - index. start
526- } )
523+ from_raw_parts (
524+ self . as_ptr ( ) . offset ( index. start as isize ) ,
525+ index. end - index. start
526+ )
527527 }
528528 }
529529}
@@ -559,10 +559,10 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
559559 assert ! ( index. start <= index. end) ;
560560 assert ! ( index. end <= self . len( ) ) ;
561561 unsafe {
562- transmute ( RawSlice {
563- data : self . as_ptr ( ) . offset ( index. start as isize ) ,
564- len : index. end - index. start
565- } )
562+ from_raw_parts_mut (
563+ self . as_mut_ptr ( ) . offset ( index. start as isize ) ,
564+ index. end - index. start
565+ )
566566 }
567567 }
568568}
@@ -731,7 +731,21 @@ macro_rules! make_slice {
731731 diff / mem:: size_of:: <$t>( )
732732 } ;
733733 unsafe {
734- transmute:: <_, $result>( RawSlice { data: $start, len: len } )
734+ from_raw_parts( $start, len)
735+ }
736+ } }
737+ }
738+
739+ macro_rules! make_mut_slice {
740+ ( $t: ty => $result: ty: $start: expr, $end: expr) => { {
741+ let diff = $end as usize - $start as usize ;
742+ let len = if mem:: size_of:: <T >( ) == 0 {
743+ diff
744+ } else {
745+ diff / mem:: size_of:: <$t>( )
746+ } ;
747+ unsafe {
748+ from_raw_parts_mut( $start, len)
735749 }
736750 } }
737751}
@@ -898,7 +912,7 @@ impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
898912impl < ' a , T > ops:: IndexMut < RangeFull > for IterMut < ' a , T > {
899913 #[ inline]
900914 fn index_mut ( & mut self , _index : & RangeFull ) -> & mut [ T ] {
901- make_slice ! ( T => & mut [ T ] : self . ptr, self . end)
915+ make_mut_slice ! ( T => & mut [ T ] : self . ptr, self . end)
902916 }
903917}
904918
@@ -912,7 +926,7 @@ impl<'a, T> IterMut<'a, T> {
912926 /// restricted lifetimes that do not consume the iterator.
913927 #[ unstable( feature = "core" ) ]
914928 pub fn into_slice ( self ) -> & ' a mut [ T ] {
915- make_slice ! ( T => & ' a mut [ T ] : self . ptr, self . end)
929+ make_mut_slice ! ( T => & ' a mut [ T ] : self . ptr, self . end)
916930 }
917931}
918932
@@ -1404,16 +1418,15 @@ impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
14041418#[ unstable( feature = "core" ) ]
14051419pub fn ref_slice < ' a , A > ( s : & ' a A ) -> & ' a [ A ] {
14061420 unsafe {
1407- transmute ( RawSlice { data : s, len : 1 } )
1421+ from_raw_parts ( s, 1 )
14081422 }
14091423}
14101424
14111425/// Converts a pointer to A into a slice of length 1 (without copying).
14121426#[ unstable( feature = "core" ) ]
14131427pub fn mut_ref_slice < ' a , A > ( s : & ' a mut A ) -> & ' a mut [ A ] {
14141428 unsafe {
1415- let ptr: * const A = transmute ( s) ;
1416- transmute ( RawSlice { data : ptr, len : 1 } )
1429+ from_raw_parts_mut ( s, 1 )
14171430 }
14181431}
14191432
0 commit comments