Rollup merge of #97871 - ChayimFriedman2:vec-iterator-unimplemented, r=compiler-errors

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).

`@rustbot` label +A-diagnostics
This commit is contained in:
Michael Goulet 2022-06-08 13:32:22 -07:00 committed by GitHub
commit 1577838151
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -40,6 +40,10 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`" 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 = "&[]", 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( on(
_Self = "&str", _Self = "&str",
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`" label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"

View file

@ -0,0 +1,4 @@
fn main() {
vec![true, false].map(|v| !v).collect::<Vec<_>>();
//~^ ERROR `Vec<bool>` is not an iterator
}

View file

@ -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> {
| ------------------------------------------------------------------------------------------------ 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`.