Skip to content

Commit 456f1ff

Browse files
Suggest using iter() or into_iter() for Vec
We cannot do that for `&Vec` because `#[rustc_on_unimplemented]` is limited (it does not clean generic instantiation for references, only for ADTs).
1 parent 47aee31 commit 456f1ff

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

library/core/src/iter/traits/iterator.rs

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
4040
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
4141
),
4242
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
43+
on(
44+
_Self = "std::vec::Vec<T, A>",
45+
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
46+
),
4347
on(
4448
_Self = "&str",
4549
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
vec![true, false].map(|v| !v).collect::<Vec<_>>();
3+
//~^ ERROR `Vec<bool>` is not an iterator
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0599]: `Vec<bool>` is not an iterator
2+
--> $DIR/vec-on-unimplemented.rs:2:23
3+
|
4+
LL | vec![true, false].map(|v| !v).collect::<Vec<_>>();
5+
| ^^^ `Vec<bool>` is not an iterator; try calling `.into_iter()` or `.iter()`
6+
|
7+
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
8+
|
9+
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
10+
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<bool>: Iterator`
11+
|
12+
= note: the following trait bounds were not satisfied:
13+
`Vec<bool>: Iterator`
14+
which is required by `&mut Vec<bool>: Iterator`
15+
`[bool]: Iterator`
16+
which is required by `&mut [bool]: Iterator`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)