@@ -728,29 +728,29 @@ macro_rules! iterator {
728
728
}
729
729
730
730
macro_rules! make_slice {
731
- ( $t: ty => $result: ty: $start: expr, $end: expr) => { {
732
- let diff = ( $end as usize ) . wrapping_sub( $start as usize ) ;
733
- let len = if mem:: size_of:: <T >( ) == 0 {
734
- diff
731
+ ( $start: expr, $end: expr) => { {
732
+ let start = $start;
733
+ let diff = ( $end as usize ) . wrapping_sub( start as usize ) ;
734
+ if size_from_ptr( start) == 0 {
735
+ // use a non-null pointer value
736
+ unsafe { from_raw_parts( 1 as * const _, diff) }
735
737
} else {
736
- diff / mem:: size_of:: <$t>( )
737
- } ;
738
- unsafe {
739
- from_raw_parts( $start, len)
738
+ let len = diff / size_from_ptr( start) ;
739
+ unsafe { from_raw_parts( start, len) }
740
740
}
741
741
} }
742
742
}
743
743
744
744
macro_rules! make_mut_slice {
745
- ( $t: ty => $result: ty: $start: expr, $end: expr) => { {
746
- let diff = ( $end as usize ) . wrapping_sub( $start as usize ) ;
747
- let len = if mem:: size_of:: <T >( ) == 0 {
748
- diff
745
+ ( $start: expr, $end: expr) => { {
746
+ let start = $start;
747
+ let diff = ( $end as usize ) . wrapping_sub( start as usize ) ;
748
+ if size_from_ptr( start) == 0 {
749
+ // use a non-null pointer value
750
+ unsafe { from_raw_parts_mut( 1 as * mut _, diff) }
749
751
} else {
750
- diff / mem:: size_of:: <$t>( )
751
- } ;
752
- unsafe {
753
- from_raw_parts_mut( $start, len)
752
+ let len = diff / size_from_ptr( start) ;
753
+ unsafe { from_raw_parts_mut( start, len) }
754
754
}
755
755
} }
756
756
}
@@ -773,7 +773,7 @@ impl<'a, T> Iter<'a, T> {
773
773
/// iterator can continue to be used while this exists.
774
774
#[ unstable( feature = "core" ) ]
775
775
pub fn as_slice ( & self ) -> & ' a [ T ] {
776
- make_slice ! ( T => & ' a [ T ] : self . ptr, self . end)
776
+ make_slice ! ( self . ptr, self . end)
777
777
}
778
778
779
779
// Helper function for Iter::nth
@@ -841,12 +841,12 @@ impl<'a, T> IterMut<'a, T> {
841
841
/// restricted lifetimes that do not consume the iterator.
842
842
#[ unstable( feature = "core" ) ]
843
843
pub fn into_slice ( self ) -> & ' a mut [ T ] {
844
- make_mut_slice ! ( T => & ' a mut [ T ] : self . ptr, self . end)
844
+ make_mut_slice ! ( self . ptr, self . end)
845
845
}
846
846
847
847
// Helper function for IterMut::nth
848
848
fn iter_nth ( & mut self , n : usize ) -> Option < & ' a mut T > {
849
- match make_mut_slice ! ( T => & ' a mut [ T ] : self . ptr, self . end) . get_mut ( n) {
849
+ match make_mut_slice ! ( self . ptr, self . end) . get_mut ( n) {
850
850
Some ( elem_ref) => unsafe {
851
851
self . ptr = slice_offset ! ( self . ptr, ( n as isize ) . wrapping_add( 1 ) ) ;
852
852
Some ( slice_ref ! ( elem_ref) )
0 commit comments