Skip to content

update array missing IntoIterator msg #82626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update array missing IntoIterator msg
  • Loading branch information
lcnr committed Mar 26, 2021
commit addc51a85f264e208385a8a1d10b6accb737ea8d
4 changes: 2 additions & 2 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
),
on(
_Self = "[]",
label = "borrow the array with `&` or call `.iter()` on it to iterate over it",
note = "arrays are not iterators, but slices like the following are: `&[1, 2, 3]`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to suggest the &?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i wasn't sure how to explain that in a concise way, as adding & changes the element type.

Do you have an idea for a second label here?

label = "arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`",
note = "see <https://github.com/rust-lang/rust/pull/65819> for more details"
),
on(
_Self = "{integral}",
Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/iterators/array-of-ranges.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@ error[E0277]: `[RangeInclusive<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:4:14
|
LL | for _ in [0..=1] {}
| ^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[RangeInclusive<{integer}>; 1]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[RangeInclusive<{integer}>; 1]`
= note: required by `into_iter`

error[E0277]: `[RangeFrom<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:6:14
|
LL | for _ in [0..] {}
| ^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[RangeFrom<{integer}>; 1]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[RangeFrom<{integer}>; 1]`
= note: required by `into_iter`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the array of ranges cases, it might make sense for us to suggest that maybe they didn't want the outer [], just the range. That seems to be the most likely intent behind the code as written.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we already had a check for those cases https://github.com/rust-lang/rust/pull/82626/files#diff-c552b2bf18fb3212fe93dd601ce487badf5e50faf9aeed4db7b0f6c22571ef01L28-L33

Maybe at some point inference broke and instead of Idx we got {integer}?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AH! It broke not because of that, but because of 07e7823 and there being a single RangeInclusive but multiple Range structs in the std. rustc_on_unimplemented has a bug, it should always be using the full path for its filtering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, fixed that


error[E0277]: `[RangeTo<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:8:14
|
LL | for _ in [..1] {}
| ^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[RangeTo<{integer}>; 1]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[RangeTo<{integer}>; 1]`
= note: required by `into_iter`

error[E0277]: `[RangeToInclusive<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:10:14
|
LL | for _ in [..=1] {}
| ^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[RangeToInclusive<{integer}>; 1]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[RangeToInclusive<{integer}>; 1]`
= note: required by `into_iter`

Expand Down Expand Up @@ -79,21 +79,21 @@ error[E0277]: `[std::ops::Range<{integer}>; 2]` is not an iterator
--> $DIR/array-of-ranges.rs:19:14
|
LL | for _ in [0..1, 2..3] {}
| ^^^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[std::ops::Range<{integer}>; 2]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[std::ops::Range<{integer}>; 2]`
= note: required by `into_iter`

error[E0277]: `[RangeInclusive<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:21:14
|
LL | for _ in [0..=1] {}
| ^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[RangeInclusive<{integer}>; 1]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[RangeInclusive<{integer}>; 1]`
= note: required by `into_iter`

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/iterators/array.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ error[E0277]: `[{integer}; 2]` is not an iterator
--> $DIR/array.rs:2:14
|
LL | for _ in [1, 2] {}
| ^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[{integer}; 2]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[{integer}; 2]`
= note: required by `into_iter`

error[E0277]: `[{integer}; 2]` is not an iterator
--> $DIR/array.rs:5:14
|
LL | for _ in x {}
| ^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[{integer}; 2]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[{integer}; 2]`
= note: required by `into_iter`

error[E0277]: `[{float}; 2]` is not an iterator
--> $DIR/array.rs:7:14
|
LL | for _ in [1.0, 2.0] {}
| ^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
| ^^^^^^^^^^ arrays do not yet implement `IntoIterator`; try using `std::array::IntoIter::new(arr)`
|
= help: the trait `Iterator` is not implemented for `[{float}; 2]`
= note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
= note: see <https://github.com/rust-lang/rust/pull/65819> for more details
= note: required because of the requirements on the impl of `IntoIterator` for `[{float}; 2]`
= note: required by `into_iter`

Expand Down