Skip to content

Commit 70d4f26

Browse files
committed
RangeFrom::step_by docs: fix example
The previous example did not do what its description said. In it panicked on integer overflow in debug mode, and went into an infinite loop in release mode (wrapping back to 0 after printing 254).
1 parent 1972c50 commit 70d4f26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libcore/iter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,13 +4252,15 @@ impl<A: Step> RangeFrom<A> {
42524252
///
42534253
/// # Examples
42544254
///
4255-
/// ```ignore
4256-
/// for i in (0u8..).step_by(2) {
4255+
/// ```
4256+
/// # #![feature(step_by)]
4257+
///
4258+
/// for i in (0u8..).step_by(2).take(10) {
42574259
/// println!("{}", i);
42584260
/// }
42594261
/// ```
42604262
///
4261-
/// This prints all even `u8` values.
4263+
/// This prints the first ten even natural integers (0 to 18).
42624264
#[unstable(feature = "step_by", reason = "recent addition",
42634265
issue = "27741")]
42644266
pub fn step_by(self, by: A) -> StepBy<A, Self> {

0 commit comments

Comments
 (0)