Closed
Description
Code
let a = [1, 2, 4, 5, 6];
for e in a {
println!("{}", e);
}
Compiler error
error[E0277]: the trait bound `[{integer}; 5]: std::iter::Iterator` is not satisfied
--> <anon>:6:5
|
6 | for e in a {
| ^ trait `[{integer}; 5]: std::iter::Iterator` not satisfied
|
= note: `[{integer}; 5]` is not an iterator; maybe try calling `.iter()` or a similar method
= note: required by `std::iter::IntoIterator::into_iter`
error: aborting due to previous error
Suggestion
Instead of suggesting .iter()
, it'd be cool if we cool if we could check if the borrowed type implements IntoIterator
and then suggest prefixing with &
. More concretely, in the example above, [T; 5]
does not implement IntoIterator
but &[T; 5]
does.