From 50e0fbc9042856527dc35a0dfd9a7716dcf69ccd Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Wed, 17 Aug 2016 14:12:19 -0400 Subject: [PATCH] accumulate vector and assert for RangeFrom and RangeInclusive examples PR #35695 for `Range` was approved, 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..`. add `fn main` wrappers to enable Rust Playground "Run" button --- src/libcore/iter/range.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 8408e5d88b4cb..66d05d81d80cd 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -263,14 +263,12 @@ impl ops::RangeFrom { /// # Examples /// /// ``` - /// # #![feature(step_by)] - /// - /// for i in (0u8..).step_by(2).take(10) { - /// println!("{}", i); + /// #![feature(step_by)] + /// fn main() { + /// let result: Vec<_> = (0..).step_by(2).take(5).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); /// } /// ``` - /// - /// This prints the first ten even natural integers (0 to 18). #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] pub fn step_by(self, by: A) -> StepBy { @@ -291,8 +289,10 @@ impl ops::Range { /// /// ``` /// #![feature(step_by)] - /// let result: Vec<_> = (0..10).step_by(2).collect(); - /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// fn main() { + /// let result: Vec<_> = (0..10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// } /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] @@ -315,20 +315,8 @@ impl ops::RangeInclusive { /// ``` /// #![feature(step_by, inclusive_range_syntax)] /// - /// for i in (0...10).step_by(2) { - /// println!("{}", i); - /// } - /// ``` - /// - /// This prints: - /// - /// ```text - /// 0 - /// 2 - /// 4 - /// 6 - /// 8 - /// 10 + /// let result: Vec<_> = (0...10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]); /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")]