File tree 2 files changed +11
-13
lines changed
2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -551,15 +551,7 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
551
551
552
552
#[ inline]
553
553
fn nth ( & mut self , n : usize ) -> Option < A > {
554
- // If we would jump over the maximum value, panic immediately.
555
- // This is consistent with behavior before the Step redesign,
556
- // even though it's inconsistent with n `next` calls.
557
- // To get consistent behavior, change it to use `forward` instead.
558
- // This change should go through FCP separately to the redesign, so is for now left as a
559
- // FIXME: make this consistent
560
- let plus_n =
561
- Step :: forward_checked ( self . start . clone ( ) , n) . expect ( "overflow in RangeFrom::nth" ) ;
562
- // The final step should always be debug-checked.
554
+ let plus_n = Step :: forward ( self . start . clone ( ) , n) ;
563
555
self . start = Step :: forward ( plus_n. clone ( ) , 1 ) ;
564
556
Some ( plus_n)
565
557
}
Original file line number Diff line number Diff line change @@ -151,10 +151,16 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
151
151
///
152
152
/// The `RangeFrom` `start..` contains all values with `x >= start`.
153
153
///
154
- /// *Note*: Currently, no overflow checking is done for the [`Iterator`]
155
- /// implementation; if you use an integer range and the integer overflows, it
156
- /// might panic in debug mode or create an endless loop in release mode. **This
157
- /// overflow behavior might change in the future.**
154
+ /// *Note*: Overflow in the [`Iterator`] implementation (when the contained
155
+ /// data type reaches its numerical limit) is allowed to panic, wrap, or
156
+ /// saturate. This behavior is defined by the implementation of the [`Step`]
157
+ /// trait. For primitive integers, this follows the normal rules, and respects
158
+ /// the overflow checks profile (panic in debug, wrap in release). Note also
159
+ /// that overflow happens earlier than you might assume: the overflow happens
160
+ /// in the call to `next` that yields the maximum value, as the range must be
161
+ /// set to a state to yield the next value.
162
+ ///
163
+ /// [`Step`]: crate::iter::Step
158
164
///
159
165
/// # Examples
160
166
///
You can’t perform that action at this time.
0 commit comments