Skip to content

Commit 9520929

Browse files
committed
Explicitely spell out behaviour on overflow for usize-returning iterators
Mention that panics are guaranteed if debug assertions are active, otherwise a wrong result might be returned.
1 parent d8861a2 commit 9520929

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/libcore/iter.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ pub trait Iterator {
106106

107107
/// Counts the number of elements in this iterator.
108108
///
109-
/// # Undefined overflow
109+
/// # Overflow Behavior
110110
///
111111
/// The method does no guarding against overflows, so counting elements of
112-
/// an iterator with more than `usize::MAX` elements is undefined.
112+
/// an iterator with more than `usize::MAX` elements either produces the
113+
/// wrong result or panics. If debug assertions are enabled, a panic is
114+
/// guaranteed.
113115
///
114116
/// # Panics
115117
///
@@ -291,10 +293,11 @@ pub trait Iterator {
291293
/// different sized integer, the `zip` function provides similar
292294
/// functionality.
293295
///
294-
/// # Undefined overflow
296+
/// # Overflow Behavior
295297
///
296298
/// The method does no guarding against overflows, so enumerating more than
297-
/// `usize::MAX` elements is undefined.
299+
/// `usize::MAX` elements either produces the wrong result or panics. If
300+
/// debug assertions are enabled, a panic is guaranteed.
298301
///
299302
/// # Panics
300303
///
@@ -695,11 +698,12 @@ pub trait Iterator {
695698
///
696699
/// Does not consume the iterator past the first found element.
697700
///
698-
/// # Undefined overflow
701+
/// # Overflow Behavior
699702
///
700-
/// The method does no guarding against overflows, so when there are more
701-
/// than `usize::MAX` non-matching elements, the overflow behaviour is
702-
/// undefined.
703+
/// The method does no guarding against overflows, so if there are more
704+
/// than `usize::MAX` non-matching elements, it either produces the wrong
705+
/// result or panics. If debug assertions are enabled, a panic is
706+
/// guaranteed.
703707
///
704708
/// # Panics
705709
///
@@ -1801,10 +1805,11 @@ pub struct Enumerate<I> {
18011805
impl<I> Iterator for Enumerate<I> where I: Iterator {
18021806
type Item = (usize, <I as Iterator>::Item);
18031807

1804-
/// # Undefined overflow
1808+
/// # Overflow Behavior
18051809
///
18061810
/// The method does no guarding against overflows, so enumerating more than
1807-
/// `usize::MAX` elements is undefined.
1811+
/// `usize::MAX` elements either produces the wrong result or panics. If
1812+
/// debug assertions are enabled, a panic is guaranteed.
18081813
///
18091814
/// # Panics
18101815
///

0 commit comments

Comments
 (0)