Skip to content
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

Suggest using iter() or into_iter() for Vec #97871

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
),
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
on(
_Self = "std::vec::Vec<T, A>",
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
),
on(
_Self = "&str",
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/iterators/vec-on-unimplemented.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
vec![true, false].map(|v| !v).collect::<Vec<_>>();
//~^ ERROR `Vec<bool>` is not an iterator
}
20 changes: 20 additions & 0 deletions src/test/ui/iterators/vec-on-unimplemented.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0599]: `Vec<bool>` is not an iterator
--> $DIR/vec-on-unimplemented.rs:2:23
|
LL | vec![true, false].map(|v| !v).collect::<Vec<_>>();
| ^^^ `Vec<bool>` is not an iterator; try calling `.into_iter()` or `.iter()`
|
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
ChayimFriedman2 marked this conversation as resolved.
Show resolved Hide resolved
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<bool>: Iterator`
|
= note: the following trait bounds were not satisfied:
`Vec<bool>: Iterator`
which is required by `&mut Vec<bool>: Iterator`
`[bool]: Iterator`
which is required by `&mut [bool]: Iterator`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.