Skip to content

Commit

Permalink
Rollup merge of rust-lang#35701 - matthew-piziak:rangefull-example-er…
Browse files Browse the repository at this point in the history
…ror, r=steveklabnik

explicitly show how iterating over `..` fails

I've also removed the `main()` wrapper, which I believe is extraneous.
LMK if that's incorrect.
  • Loading branch information
Jonathan Turner authored Aug 20, 2016
2 parents fcdb9ce + 469b7fd commit 68a4ec2
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,17 +1467,30 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
///
/// # Examples
///
/// The `..` syntax is a `RangeFull`:
///
/// ```
/// assert_eq!((..), std::ops::RangeFull);
/// ```
/// fn main() {
/// assert_eq!((..), std::ops::RangeFull);
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
/// assert_eq!(arr[ ..3], [0,1,2 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3]);
/// assert_eq!(arr[1..3], [ 1,2 ]);
/// It does not have an `IntoIterator` implementation, so you can't use it in a
/// `for` loop directly. This won't compile:
///
/// ```ignore
/// for i in .. {
/// // ...
/// }
/// ```
///
/// Used as a slicing index, `RangeFull` produces the full array as a slice.
///
/// ```
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
/// assert_eq!(arr[ ..3], [0,1,2 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3]);
/// assert_eq!(arr[1..3], [ 1,2 ]);
/// ```
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeFull;
Expand Down

0 comments on commit 68a4ec2

Please sign in to comment.