Skip to content

Commit 25efe72

Browse files
Adjust docs and tests for new IntoIterator impl for arrays
1 parent e6bccc9 commit 25efe72

File tree

5 files changed

+8
-169
lines changed

5 files changed

+8
-169
lines changed

library/std/src/primitive_docs.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ mod prim_pointer {}
498498
/// - [`Copy`]
499499
/// - [`Clone`]
500500
/// - [`Debug`]
501-
/// - [`IntoIterator`] (implemented for `&[T; N]` and `&mut [T; N]`)
501+
/// - [`IntoIterator`] (implemented for `[T; N]`, `&[T; N]` and `&mut [T; N]`)
502502
/// - [`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]
503503
/// - [`Hash`]
504504
/// - [`AsRef`], [`AsMut`]
@@ -526,31 +526,16 @@ mod prim_pointer {}
526526
/// assert_eq!([1, 2], &array[1..]);
527527
///
528528
/// // This loop prints: 0 1 2
529-
/// for x in &array {
529+
/// for x in array {
530530
/// print!("{} ", x);
531531
/// }
532532
/// ```
533533
///
534-
/// An array itself is not iterable:
535-
///
536-
/// ```compile_fail,E0277
537-
/// let array: [i32; 3] = [0; 3];
538-
///
539-
/// for x in array { }
540-
/// // error: the trait bound `[i32; 3]: std::iter::Iterator` is not satisfied
541-
/// ```
542-
///
543-
/// The solution is to coerce the array to a slice by calling a slice method:
534+
/// You can also iterate over reference to the array's elements:
544535
///
545536
/// ```
546-
/// # let array: [i32; 3] = [0; 3];
547-
/// for x in array.iter() { }
548-
/// ```
549-
///
550-
/// You can also use the array reference's [`IntoIterator`] implementation:
537+
/// let array: [i32; 3] = [0; 3];
551538
///
552-
/// ```
553-
/// # let array: [i32; 3] = [0; 3];
554539
/// for x in &array { }
555540
/// ```
556541
///
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1+
// check-pass
2+
13
fn main() {
24
for _ in [0..1] {}
3-
//~^ ERROR is not an iterator
45
for _ in [0..=1] {}
5-
//~^ ERROR is not an iterator
66
for _ in [0..] {}
7-
//~^ ERROR is not an iterator
87
for _ in [..1] {}
9-
//~^ ERROR is not an iterator
108
for _ in [..=1] {}
11-
//~^ ERROR is not an iterator
129
let start = 0;
1310
let end = 0;
1411
for _ in [start..end] {}
15-
//~^ ERROR is not an iterator
1612
let array_of_range = [start..end];
1713
for _ in array_of_range {}
18-
//~^ ERROR is not an iterator
1914
for _ in [0..1, 2..3] {}
20-
//~^ ERROR is not an iterator
2115
for _ in [0..=1] {}
22-
//~^ ERROR is not an iterator
2316
}

src/test/ui/iterators/array-of-ranges.stderr

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/test/ui/iterators/array.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
// check-pass
2+
13
fn main() {
24
for _ in [1, 2] {}
3-
//~^ ERROR is not an iterator
45
let x = [1, 2];
56
for _ in x {}
6-
//~^ ERROR is not an iterator
77
for _ in [1.0, 2.0] {}
8-
//~^ ERROR is not an iterator
98
}

src/test/ui/iterators/array.stderr

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)