Skip to content

Commit 80571b8

Browse files
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 528c6f3 + 28f057d commit 80571b8

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/libcore/iter/range.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,12 @@ impl<A: Step> ops::RangeFrom<A> {
267267
/// # Examples
268268
///
269269
/// ```
270-
/// # #![feature(step_by)]
271-
///
272-
/// for i in (0u8..).step_by(2).take(10) {
273-
/// println!("{}", i);
270+
/// #![feature(step_by)]
271+
/// fn main() {
272+
/// let result: Vec<_> = (0..).step_by(2).take(5).collect();
273+
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
274274
/// }
275275
/// ```
276-
///
277-
/// This prints the first ten even natural integers (0 to 18).
278276
#[unstable(feature = "step_by", reason = "recent addition",
279277
issue = "27741")]
280278
pub fn step_by(self, by: A) -> StepBy<A, Self> {
@@ -295,8 +293,10 @@ impl<A: Step> ops::Range<A> {
295293
///
296294
/// ```
297295
/// #![feature(step_by)]
298-
/// let result: Vec<_> = (0..10).step_by(2).collect();
299-
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
296+
/// fn main() {
297+
/// let result: Vec<_> = (0..10).step_by(2).collect();
298+
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
299+
/// }
300300
/// ```
301301
#[unstable(feature = "step_by", reason = "recent addition",
302302
issue = "27741")]
@@ -319,20 +319,8 @@ impl<A: Step> ops::RangeInclusive<A> {
319319
/// ```
320320
/// #![feature(step_by, inclusive_range_syntax)]
321321
///
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
322+
/// let result: Vec<_> = (0...10).step_by(2).collect();
323+
/// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]);
336324
/// ```
337325
#[unstable(feature = "step_by", reason = "recent addition",
338326
issue = "27741")]

0 commit comments

Comments
 (0)