@@ -1629,11 +1629,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Chunks<'a, T> {
1629
1629
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1630
1630
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1631
1631
pub struct ChunksMut < ' a , T : ' a > {
1632
- // This slice pointer must point at a valid region of T with at least length v.len(). Normally,
1633
- // those requirements would mean that we could instead use a &mut [T] here, but we cannot
1634
- // because __iterator_get_unchecked needs to return &mut [T], which guarantees certain aliasing
1635
- // properties that we cannot uphold if we hold on to the full original &mut [T]. Wrapping a raw
1636
- // slice instead lets us hand out non-overlapping &mut [T] subslices of the slice we wrap.
1632
+ /// # Safety
1633
+ /// This slice pointer must point at a valid region of `T` with at least length `v.len()`. Normally,
1634
+ /// those requirements would mean that we could instead use a `&mut [T]` here, but we cannot
1635
+ /// because `__iterator_get_unchecked` needs to return `&mut [T]`, which guarantees certain aliasing
1636
+ /// properties that we cannot uphold if we hold on to the full original `&mut [T]`. Wrapping a raw
1637
+ /// slice instead lets us hand out non-overlapping `&mut [T]` subslices of the slice we wrap.
1637
1638
v : * mut [ T ] ,
1638
1639
chunk_size : usize ,
1639
1640
_marker : PhantomData < & ' a mut T > ,
@@ -1656,7 +1657,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
1656
1657
None
1657
1658
} else {
1658
1659
let sz = cmp:: min ( self . v . len ( ) , self . chunk_size ) ;
1659
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
1660
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
1660
1661
let ( head, tail) = unsafe { self . v . split_at_mut ( sz) } ;
1661
1662
self . v = tail;
1662
1663
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -1692,9 +1693,9 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
1692
1693
Some ( sum) => cmp:: min ( self . v . len ( ) , sum) ,
1693
1694
None => self . v . len ( ) ,
1694
1695
} ;
1695
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
1696
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
1696
1697
let ( head, tail) = unsafe { self . v . split_at_mut ( end) } ;
1697
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
1698
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
1698
1699
let ( _, nth) = unsafe { head. split_at_mut ( start) } ;
1699
1700
self . v = tail;
1700
1701
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -1715,7 +1716,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
1715
1716
1716
1717
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> Self :: Item {
1717
1718
let start = idx * self . chunk_size ;
1718
- // SAFETY: see comments for `Chunks::__iterator_get_unchecked`.
1719
+ // SAFETY: see comments for `Chunks::__iterator_get_unchecked` and `self.v` .
1719
1720
//
1720
1721
// Also note that the caller also guarantees that we're never called
1721
1722
// with the same index again, and that no other methods that will
@@ -1758,9 +1759,9 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
1758
1759
Some ( res) => cmp:: min ( self . v . len ( ) , res) ,
1759
1760
None => self . v . len ( ) ,
1760
1761
} ;
1761
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
1762
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
1762
1763
let ( temp, _tail) = unsafe { self . v . split_at_mut ( end) } ;
1763
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
1764
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
1764
1765
let ( head, nth_back) = unsafe { temp. split_at_mut ( start) } ;
1765
1766
self . v = head;
1766
1767
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -1970,11 +1971,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExact<'a, T> {
1970
1971
#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1971
1972
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1972
1973
pub struct ChunksExactMut < ' a , T : ' a > {
1973
- // This slice pointer must point at a valid region of T with at least length v.len(). Normally,
1974
- // those requirements would mean that we could instead use a &mut [T] here, but we cannot
1975
- // because __iterator_get_unchecked needs to return &mut [T], which guarantees certain aliasing
1976
- // properties that we cannot uphold if we hold on to the full original &mut [T]. Wrapping a raw
1977
- // slice instead lets us hand out non-overlapping &mut [T] subslices of the slice we wrap.
1974
+ /// # Safety
1975
+ /// This slice pointer must point at a valid region of `T` with at least length `v.len()`. Normally,
1976
+ /// those requirements would mean that we could instead use a `&mut [T]` here, but we cannot
1977
+ /// because `__iterator_get_unchecked` needs to return `&mut [T]`, which guarantees certain aliasing
1978
+ /// properties that we cannot uphold if we hold on to the full original `&mut [T]`. Wrapping a raw
1979
+ /// slice instead lets us hand out non-overlapping `&mut [T]` subslices of the slice we wrap.
1978
1980
v : * mut [ T ] ,
1979
1981
rem : & ' a mut [ T ] , // The iterator never yields from here, so this can be unique
1980
1982
chunk_size : usize ,
@@ -2036,7 +2038,7 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> {
2036
2038
self . v = & mut [ ] ;
2037
2039
None
2038
2040
} else {
2039
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
2041
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
2040
2042
let ( _, snd) = unsafe { self . v . split_at_mut ( start) } ;
2041
2043
self . v = snd;
2042
2044
self . next ( )
@@ -2050,7 +2052,7 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> {
2050
2052
2051
2053
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> Self :: Item {
2052
2054
let start = idx * self . chunk_size ;
2053
- // SAFETY: see comments for `ChunksMut ::__iterator_get_unchecked`.
2055
+ // SAFETY: see comments for `Chunks ::__iterator_get_unchecked` and `self.v `.
2054
2056
unsafe { from_raw_parts_mut ( self . v . as_mut_ptr ( ) . add ( start) , self . chunk_size ) }
2055
2057
}
2056
2058
}
@@ -2079,9 +2081,9 @@ impl<'a, T> DoubleEndedIterator for ChunksExactMut<'a, T> {
2079
2081
} else {
2080
2082
let start = ( len - 1 - n) * self . chunk_size ;
2081
2083
let end = start + self . chunk_size ;
2082
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
2084
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
2083
2085
let ( temp, _tail) = unsafe { mem:: replace ( & mut self . v , & mut [ ] ) . split_at_mut ( end) } ;
2084
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
2086
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
2085
2087
let ( head, nth_back) = unsafe { temp. split_at_mut ( start) } ;
2086
2088
self . v = head;
2087
2089
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -2669,11 +2671,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunks<'a, T> {
2669
2671
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2670
2672
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
2671
2673
pub struct RChunksMut < ' a , T : ' a > {
2672
- // This slice pointer must point at a valid region of T with at least length v.len(). Normally,
2673
- // those requirements would mean that we could instead use a &mut [T] here, but we cannot
2674
- // because __iterator_get_unchecked needs to return &mut [T], which guarantees certain aliasing
2675
- // properties that we cannot uphold if we hold on to the full original &mut [T]. Wrapping a raw
2676
- // slice instead lets us hand out non-overlapping &mut [T] subslices of the slice we wrap.
2674
+ /// # Safety
2675
+ /// This slice pointer must point at a valid region of `T` with at least length `v.len()`. Normally,
2676
+ /// those requirements would mean that we could instead use a `&mut [T]` here, but we cannot
2677
+ /// because `__iterator_get_unchecked` needs to return `&mut [T]`, which guarantees certain aliasing
2678
+ /// properties that we cannot uphold if we hold on to the full original `&mut [T]`. Wrapping a raw
2679
+ /// slice instead lets us hand out non-overlapping `&mut [T]` subslices of the slice we wrap.
2677
2680
v : * mut [ T ] ,
2678
2681
chunk_size : usize ,
2679
2682
_marker : PhantomData < & ' a mut T > ,
@@ -2770,7 +2773,7 @@ impl<'a, T> Iterator for RChunksMut<'a, T> {
2770
2773
Some ( start) => start,
2771
2774
} ;
2772
2775
// SAFETY: see comments for `RChunks::__iterator_get_unchecked` and
2773
- // `ChunksMut::__iterator_get_unchecked`
2776
+ // `ChunksMut::__iterator_get_unchecked`, `self.v`.
2774
2777
unsafe { from_raw_parts_mut ( self . v . as_mut_ptr ( ) . add ( start) , end - start) }
2775
2778
}
2776
2779
}
@@ -2803,9 +2806,9 @@ impl<'a, T> DoubleEndedIterator for RChunksMut<'a, T> {
2803
2806
let offset_from_end = ( len - 1 - n) * self . chunk_size ;
2804
2807
let end = self . v . len ( ) - offset_from_end;
2805
2808
let start = end. saturating_sub ( self . chunk_size ) ;
2806
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
2809
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
2807
2810
let ( tmp, tail) = unsafe { self . v . split_at_mut ( end) } ;
2808
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
2811
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
2809
2812
let ( _, nth_back) = unsafe { tmp. split_at_mut ( start) } ;
2810
2813
self . v = tail;
2811
2814
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -3018,11 +3021,12 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
3018
3021
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
3019
3022
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
3020
3023
pub struct RChunksExactMut < ' a , T : ' a > {
3021
- // This slice pointer must point at a valid region of T with at least length v.len(). Normally,
3022
- // those requirements would mean that we could instead use a &mut [T] here, but we cannot
3023
- // because __iterator_get_unchecked needs to return &mut [T], which guarantees certain aliasing
3024
- // properties that we cannot uphold if we hold on to the full original &mut [T]. Wrapping a raw
3025
- // slice instead lets us hand out non-overlapping &mut [T] subslices of the slice we wrap.
3024
+ /// # Safety
3025
+ /// This slice pointer must point at a valid region of `T` with at least length `v.len()`. Normally,
3026
+ /// those requirements would mean that we could instead use a `&mut [T]` here, but we cannot
3027
+ /// because `__iterator_get_unchecked` needs to return `&mut [T]`, which guarantees certain aliasing
3028
+ /// properties that we cannot uphold if we hold on to the full original `&mut [T]`. Wrapping a raw
3029
+ /// slice instead lets us hand out non-overlapping `&mut [T]` subslices of the slice we wrap.
3026
3030
v : * mut [ T ] ,
3027
3031
rem : & ' a mut [ T ] ,
3028
3032
chunk_size : usize ,
@@ -3057,7 +3061,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
3057
3061
None
3058
3062
} else {
3059
3063
let len = self . v . len ( ) ;
3060
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
3064
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
3061
3065
let ( head, tail) = unsafe { self . v . split_at_mut ( len - self . chunk_size ) } ;
3062
3066
self . v = head;
3063
3067
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -3084,7 +3088,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
3084
3088
None
3085
3089
} else {
3086
3090
let len = self . v . len ( ) ;
3087
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
3091
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
3088
3092
let ( fst, _) = unsafe { self . v . split_at_mut ( len - end) } ;
3089
3093
self . v = fst;
3090
3094
self . next ( )
@@ -3099,7 +3103,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
3099
3103
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> Self :: Item {
3100
3104
let end = self . v . len ( ) - idx * self . chunk_size ;
3101
3105
let start = end - self . chunk_size ;
3102
- // SAFETY: see comments for `RChunksMut::__iterator_get_unchecked`.
3106
+ // SAFETY: see comments for `RChunksMut::__iterator_get_unchecked` and `self.v` .
3103
3107
unsafe { from_raw_parts_mut ( self . v . as_mut_ptr ( ) . add ( start) , self . chunk_size ) }
3104
3108
}
3105
3109
}
@@ -3111,7 +3115,7 @@ impl<'a, T> DoubleEndedIterator for RChunksExactMut<'a, T> {
3111
3115
if self . v . len ( ) < self . chunk_size {
3112
3116
None
3113
3117
} else {
3114
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
3118
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
3115
3119
let ( head, tail) = unsafe { self . v . split_at_mut ( self . chunk_size ) } ;
3116
3120
self . v = tail;
3117
3121
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -3131,9 +3135,9 @@ impl<'a, T> DoubleEndedIterator for RChunksExactMut<'a, T> {
3131
3135
let offset = ( len - n) * self . chunk_size ;
3132
3136
let start = self . v . len ( ) - offset;
3133
3137
let end = start + self . chunk_size ;
3134
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
3138
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
3135
3139
let ( tmp, tail) = unsafe { self . v . split_at_mut ( end) } ;
3136
- // SAFETY: This type ensures that any split_at_mut on self.v is valid.
3140
+ // SAFETY: The self.v contract ensures that any split_at_mut is valid.
3137
3141
let ( _, nth_back) = unsafe { tmp. split_at_mut ( start) } ;
3138
3142
self . v = tail;
3139
3143
// SAFETY: Nothing else points to or will point to the contents of this slice.
@@ -3220,11 +3224,7 @@ where
3220
3224
let mut len = 1 ;
3221
3225
let mut iter = self . slice . windows ( 2 ) ;
3222
3226
while let Some ( [ l, r] ) = iter. next ( ) {
3223
- if ( self . predicate ) ( l, r) {
3224
- len += 1
3225
- } else {
3226
- break ;
3227
- }
3227
+ if ( self . predicate ) ( l, r) { len += 1 } else { break }
3228
3228
}
3229
3229
let ( head, tail) = self . slice . split_at ( len) ;
3230
3230
self . slice = tail;
@@ -3256,11 +3256,7 @@ where
3256
3256
let mut len = 1 ;
3257
3257
let mut iter = self . slice . windows ( 2 ) ;
3258
3258
while let Some ( [ l, r] ) = iter. next_back ( ) {
3259
- if ( self . predicate ) ( l, r) {
3260
- len += 1
3261
- } else {
3262
- break ;
3263
- }
3259
+ if ( self . predicate ) ( l, r) { len += 1 } else { break }
3264
3260
}
3265
3261
let ( head, tail) = self . slice . split_at ( self . slice . len ( ) - len) ;
3266
3262
self . slice = head;
@@ -3315,11 +3311,7 @@ where
3315
3311
let mut len = 1 ;
3316
3312
let mut iter = self . slice . windows ( 2 ) ;
3317
3313
while let Some ( [ l, r] ) = iter. next ( ) {
3318
- if ( self . predicate ) ( l, r) {
3319
- len += 1
3320
- } else {
3321
- break ;
3322
- }
3314
+ if ( self . predicate ) ( l, r) { len += 1 } else { break }
3323
3315
}
3324
3316
let slice = mem:: take ( & mut self . slice ) ;
3325
3317
let ( head, tail) = slice. split_at_mut ( len) ;
@@ -3352,11 +3344,7 @@ where
3352
3344
let mut len = 1 ;
3353
3345
let mut iter = self . slice . windows ( 2 ) ;
3354
3346
while let Some ( [ l, r] ) = iter. next_back ( ) {
3355
- if ( self . predicate ) ( l, r) {
3356
- len += 1
3357
- } else {
3358
- break ;
3359
- }
3347
+ if ( self . predicate ) ( l, r) { len += 1 } else { break }
3360
3348
}
3361
3349
let slice = mem:: take ( & mut self . slice ) ;
3362
3350
let ( head, tail) = slice. split_at_mut ( slice. len ( ) - len) ;
0 commit comments