Skip to content

Commit 05fb19c

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35701 - matthew-piziak:rangefull-example-error, 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.
2 parents 413ada3 + 469b7fd commit 05fb19c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/libcore/ops.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,17 +1467,30 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
14671467
///
14681468
/// # Examples
14691469
///
1470+
/// The `..` syntax is a `RangeFull`:
1471+
///
1472+
/// ```
1473+
/// assert_eq!((..), std::ops::RangeFull);
14701474
/// ```
1471-
/// fn main() {
1472-
/// assert_eq!((..), std::ops::RangeFull);
14731475
///
1474-
/// let arr = [0, 1, 2, 3];
1475-
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
1476-
/// assert_eq!(arr[ ..3], [0,1,2 ]);
1477-
/// assert_eq!(arr[1.. ], [ 1,2,3]);
1478-
/// assert_eq!(arr[1..3], [ 1,2 ]);
1476+
/// It does not have an `IntoIterator` implementation, so you can't use it in a
1477+
/// `for` loop directly. This won't compile:
1478+
///
1479+
/// ```ignore
1480+
/// for i in .. {
1481+
/// // ...
14791482
/// }
14801483
/// ```
1484+
///
1485+
/// Used as a slicing index, `RangeFull` produces the full array as a slice.
1486+
///
1487+
/// ```
1488+
/// let arr = [0, 1, 2, 3];
1489+
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
1490+
/// assert_eq!(arr[ ..3], [0,1,2 ]);
1491+
/// assert_eq!(arr[1.. ], [ 1,2,3]);
1492+
/// assert_eq!(arr[1..3], [ 1,2 ]);
1493+
/// ```
14811494
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
14821495
#[stable(feature = "rust1", since = "1.0.0")]
14831496
pub struct RangeFull;

0 commit comments

Comments
 (0)