Skip to content

Commit c0c2f33

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35758 - matthew-piziak:vec-assert-over-println-remaining, r=GuillaumeGomez
accumulate vector and assert for RangeFrom and RangeInclusive examples PR rust-lang#35695 for `Range` was merged, so it seems that this side-effect-free style is preferred for Range* examples. This PR performs the same translation for `RangeFrom` and `RangeInclusive`. It also removes what looks to be an erroneously commented line for `#![feature(step_by)]`, and an unnecessary primitive-type annotation in `0u8..`.
2 parents f60a669 + 95c53b1 commit c0c2f33

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/libcore/iter/range.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,11 @@ impl<A: Step> ops::RangeFrom<A> {
267267
/// # Examples
268268
///
269269
/// ```
270-
/// # #![feature(step_by)]
270+
/// #![feature(step_by)]
271271
///
272-
/// for i in (0u8..).step_by(2).take(10) {
273-
/// println!("{}", i);
274-
/// }
272+
/// let result: Vec<_> = (0..).step_by(2).take(5).collect();
273+
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
275274
/// ```
276-
///
277-
/// This prints the first ten even natural integers (0 to 18).
278275
#[unstable(feature = "step_by", reason = "recent addition",
279276
issue = "27741")]
280277
pub fn step_by(self, by: A) -> StepBy<A, Self> {
@@ -319,20 +316,8 @@ impl<A: Step> ops::RangeInclusive<A> {
319316
/// ```
320317
/// #![feature(step_by, inclusive_range_syntax)]
321318
///
322-
/// for i in (0...10).step_by(2) {
323-
/// println!("{}", i);
324-
/// }
325-
/// ```
326-
///
327-
/// This prints:
328-
///
329-
/// ```text
330-
/// 0
331-
/// 2
332-
/// 4
333-
/// 6
334-
/// 8
335-
/// 10
319+
/// let result: Vec<_> = (0...10).step_by(2).collect();
320+
/// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]);
336321
/// ```
337322
#[unstable(feature = "step_by", reason = "recent addition",
338323
issue = "27741")]

0 commit comments

Comments
 (0)