Skip to content

Commit 85e997a

Browse files
committed
rollup merge of #23899: steveklabnik/gh23851
Conflicts: src/libcore/iter.rs
2 parents 6659865 + cf56162 commit 85e997a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/libcore/iter.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,22 @@
2626
//! in reverse, the `FromIterator` trait for creating a container from an
2727
//! iterator, and much more.
2828
//!
29-
//! ## Rust's `for` loop
29+
//! # Rust's `for` loop
3030
//!
31-
//! The special syntax used by rust's `for` loop is based around the `Iterator`
32-
//! trait defined in this module. For loops can be viewed as a syntactical
33-
//! expansion into a `loop`, for example, the `for` loop in this example is
34-
//! essentially translated to the `loop` below.
31+
//! The special syntax used by rust's `for` loop is based around the
32+
//! `IntoIterator` trait defined in this module. `for` loops can be viewed as a
33+
//! syntactical expansion into a `loop`, for example, the `for` loop in this
34+
//! example is essentially translated to the `loop` below.
3535
//!
3636
//! ```
3737
//! let values = vec![1, 2, 3];
3838
//!
39-
//! // "Syntactical sugar" taking advantage of an iterator
40-
//! for &x in values.iter() {
39+
//! for x in values {
4140
//! println!("{}", x);
4241
//! }
4342
//!
4443
//! // Rough translation of the iteration without a `for` iterator.
45-
//! let mut it = values.iter();
44+
//! let mut it = values.into_iter();
4645
//! loop {
4746
//! match it.next() {
4847
//! Some(&x) => {
@@ -53,7 +52,8 @@
5352
//! }
5453
//! ```
5554
//!
56-
//! This `for` loop syntax can be applied to any iterator over any type.
55+
//! Because `Iterator`s implement `IntoIterator`, this `for` loop syntax can be applied to any
56+
//! iterator over any type.
5757
5858
#![stable(feature = "rust1", since = "1.0.0")]
5959

@@ -1057,6 +1057,9 @@ pub trait FromIterator<A> {
10571057
}
10581058

10591059
/// Conversion into an `Iterator`
1060+
///
1061+
/// Implementing this trait allows you to use your type with Rust's `for` loop. See
1062+
/// the [module level documentation](../index.html) for more details.
10601063
#[stable(feature = "rust1", since = "1.0.0")]
10611064
pub trait IntoIterator {
10621065
/// The type of the elements being iterated

0 commit comments

Comments
 (0)