@@ -520,10 +520,10 @@ impl<T> ops::Index<ops::Range<usize>> for [T] {
520
520
assert ! ( index. start <= index. end) ;
521
521
assert ! ( index. end <= self . len( ) ) ;
522
522
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
+ )
527
527
}
528
528
}
529
529
}
@@ -559,10 +559,10 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
559
559
assert ! ( index. start <= index. end) ;
560
560
assert ! ( index. end <= self . len( ) ) ;
561
561
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
+ )
566
566
}
567
567
}
568
568
}
@@ -731,7 +731,21 @@ macro_rules! make_slice {
731
731
diff / mem:: size_of:: <$t>( )
732
732
} ;
733
733
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)
735
749
}
736
750
} }
737
751
}
@@ -898,7 +912,7 @@ impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
898
912
impl < ' a , T > ops:: IndexMut < RangeFull > for IterMut < ' a , T > {
899
913
#[ inline]
900
914
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)
902
916
}
903
917
}
904
918
@@ -912,7 +926,7 @@ impl<'a, T> IterMut<'a, T> {
912
926
/// restricted lifetimes that do not consume the iterator.
913
927
#[ unstable( feature = "core" ) ]
914
928
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)
916
930
}
917
931
}
918
932
@@ -1404,16 +1418,15 @@ impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
1404
1418
#[ unstable( feature = "core" ) ]
1405
1419
pub fn ref_slice < ' a , A > ( s : & ' a A ) -> & ' a [ A ] {
1406
1420
unsafe {
1407
- transmute ( RawSlice { data : s, len : 1 } )
1421
+ from_raw_parts ( s, 1 )
1408
1422
}
1409
1423
}
1410
1424
1411
1425
/// Converts a pointer to A into a slice of length 1 (without copying).
1412
1426
#[ unstable( feature = "core" ) ]
1413
1427
pub fn mut_ref_slice < ' a , A > ( s : & ' a mut A ) -> & ' a mut [ A ] {
1414
1428
unsafe {
1415
- let ptr: * const A = transmute ( s) ;
1416
- transmute ( RawSlice { data : ptr, len : 1 } )
1429
+ from_raw_parts_mut ( s, 1 )
1417
1430
}
1418
1431
}
1419
1432
0 commit comments