@@ -61,6 +61,8 @@ macro_rules! step_integer_impls {
61
61
impl Step for $narrower_unsigned {
62
62
#[ inline]
63
63
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
64
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on
65
+ // this being correct!
64
66
if * start < * end {
65
67
// This relies on $narrower_unsigned <= usize
66
68
Some ( ( * end - * start) as usize )
@@ -92,6 +94,8 @@ macro_rules! step_integer_impls {
92
94
impl Step for $narrower_signed {
93
95
#[ inline]
94
96
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
97
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on
98
+ // this being correct!
95
99
if * start < * end {
96
100
// This relies on $narrower_signed <= usize
97
101
//
@@ -156,6 +160,8 @@ macro_rules! step_integer_impls {
156
160
impl Step for $wider_unsigned {
157
161
#[ inline]
158
162
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
163
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on
164
+ // this being correct!
159
165
if * start < * end {
160
166
usize :: try_from( * end - * start) . ok( )
161
167
} else {
@@ -180,6 +186,8 @@ macro_rules! step_integer_impls {
180
186
impl Step for $wider_signed {
181
187
#[ inline]
182
188
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
189
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on
190
+ // this being correct!
183
191
if * start < * end {
184
192
match end. checked_sub( * start) {
185
193
Some ( diff) => usize :: try_from( diff) . ok( ) ,
@@ -274,6 +282,7 @@ impl<A: Step> Iterator for ops::Range<A> {
274
282
275
283
#[ inline]
276
284
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
285
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on this being correct!
277
286
match Step :: steps_between ( & self . start , & self . end ) {
278
287
Some ( hint) => ( hint, Some ( hint) ) ,
279
288
None => ( 0 , None )
@@ -306,8 +315,14 @@ range_incl_exact_iter_impl!(u8 u16 i8 i16);
306
315
//
307
316
// They need to guarantee that .size_hint() is either exact, or that
308
317
// the upper bound is None when it does not fit the type limits.
309
- range_trusted_len_impl ! ( usize isize u8 i8 u16 i16 u32 i32 i64 u64 ) ;
310
- range_incl_trusted_len_impl ! ( usize isize u8 i8 u16 i16 u32 i32 i64 u64 ) ;
318
+ range_trusted_len_impl ! {
319
+ usize u8 u16 u32 u64 u128
320
+ isize i8 i16 i32 i64 i128
321
+ }
322
+ range_incl_trusted_len_impl ! {
323
+ usize u8 u16 u32 u64 u128
324
+ isize i8 i16 i32 i64 i128
325
+ }
311
326
312
327
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
313
328
impl < A : Step > DoubleEndedIterator for ops:: Range < A > {
@@ -387,6 +402,8 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
387
402
388
403
#[ inline]
389
404
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
405
+ // NOTE: the safety of `unsafe impl TrustedLen` depends on this being correct!
406
+
390
407
if !( self . start <= self . end ) {
391
408
return ( 0 , Some ( 0 ) ) ;
392
409
}
0 commit comments