about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorMatthew Piziak <matthew.piziak@gmail.com>2016-08-17 14:12:19 -0400
committerMatthew Piziak <matthew.piziak@gmail.com>2016-08-26 11:54:32 -0400
commit50e0fbc9042856527dc35a0dfd9a7716dcf69ccd (patch)
tree94435efec5aa505fe631296b5096c6689d411334 /src/libcore
parenteaf71f8d1034f16140791f566cab3f3c9a0bf96a (diff)
downloadrust-50e0fbc9042856527dc35a0dfd9a7716dcf69ccd.tar.gz
rust-50e0fbc9042856527dc35a0dfd9a7716dcf69ccd.zip
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
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/iter/range.rs32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs
index 8408e5d88b4..66d05d81d80 100644
--- a/src/libcore/iter/range.rs
+++ b/src/libcore/iter/range.rs
@@ -263,14 +263,12 @@ impl<A: Step> ops::RangeFrom<A> {
     /// # 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<A, Self> {
@@ -291,8 +289,10 @@ impl<A: Step> ops::Range<A> {
     ///
     /// ```
     /// #![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<A: Step> ops::RangeInclusive<A> {
     /// ```
     /// #![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")]