Skip to content

Commit 40ef965

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 4473130 + 50e0fbc commit 40ef965

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
@@ -263,14 +263,12 @@ impl<A: Step> ops::RangeFrom<A> {
263263
/// # Examples
264264
///
265265
/// ```
266-
/// # #![feature(step_by)]
267-
///
268-
/// for i in (0u8..).step_by(2).take(10) {
269-
/// println!("{}", i);
266+
/// #![feature(step_by)]
267+
/// fn main() {
268+
/// let result: Vec<_> = (0..).step_by(2).take(5).collect();
269+
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
270270
/// }
271271
/// ```
272-
///
273-
/// This prints the first ten even natural integers (0 to 18).
274272
#[unstable(feature = "step_by", reason = "recent addition",
275273
issue = "27741")]
276274
pub fn step_by(self, by: A) -> StepBy<A, Self> {
@@ -291,8 +289,10 @@ impl<A: Step> ops::Range<A> {
291289
///
292290
/// ```
293291
/// #![feature(step_by)]
294-
/// let result: Vec<_> = (0..10).step_by(2).collect();
295-
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
292+
/// fn main() {
293+
/// let result: Vec<_> = (0..10).step_by(2).collect();
294+
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
295+
/// }
296296
/// ```
297297
#[unstable(feature = "step_by", reason = "recent addition",
298298
issue = "27741")]
@@ -315,20 +315,8 @@ impl<A: Step> ops::RangeInclusive<A> {
315315
/// ```
316316
/// #![feature(step_by, inclusive_range_syntax)]
317317
///
318-
/// for i in (0...10).step_by(2) {
319-
/// println!("{}", i);
320-
/// }
321-
/// ```
322-
///
323-
/// This prints:
324-
///
325-
/// ```text
326-
/// 0
327-
/// 2
328-
/// 4
329-
/// 6
330-
/// 8
331-
/// 10
318+
/// let result: Vec<_> = (0...10).step_by(2).collect();
319+
/// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]);
332320
/// ```
333321
#[unstable(feature = "step_by", reason = "recent addition",
334322
issue = "27741")]

0 commit comments

Comments
 (0)