File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 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> {
551551
552552 #[ inline]
553553 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) ;
563555 self . start = Step :: forward ( plus_n. clone ( ) , 1 ) ;
564556 Some ( plus_n)
565557 }
Original file line number Diff line number Diff line change @@ -151,10 +151,16 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
151151///
152152/// The `RangeFrom` `start..` contains all values with `x >= start`.
153153///
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
158164///
159165/// # Examples
160166///
You can’t perform that action at this time.
0 commit comments