Given the following code: play
trait MyIterator : Iterator {}
fn main() {
let _ = MyIterator::next;
//let _ = MyIterator<Item=()>::next;
}
The current output is:
error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
--> src/main.rs:4:13
|
4 | let _ = MyIterator::next;
| ^^^^^^^^^^ help: specify the associated type: `MyIterator<Item = Type>`
But when when I write let _ = MyIterator<Item=()>::next;, it gets interpreted as comparison expressions like (MyIterator < Item) = (() > ::next) and it fails to compile with a lot of "cannot find value Item in this scope" and "cannot find crate next in the list of imported crates". The suggestion is confusing because it is unclear how to apply it.
The error goes away if you use Iterator directly: let _ = Iterator::next; produces the error one would expect:
error[E0283]: type annotations needed for `for<'r> fn(&'r mut Self) -> Option<<Self as Iterator>::Item>`
--> src/main.rs:2:13
|
2 | let _ = Iterator::next;
| - ^^^^^^^^^^^^^^ cannot infer type
| |
| consider giving this pattern the explicit type `for<'r> fn(&'r mut Self) -> Option<<Self as Iterator>::Item>`, with the type parameters specified
|
= note: cannot satisfy `_: Iterator`
note: required by `std::iter::Iterator::next`
Given the following code: play
The current output is:
But when when I write
let _ = MyIterator<Item=()>::next;, it gets interpreted as comparison expressions like(MyIterator < Item) = (() > ::next)and it fails to compile with a lot of "cannot find valueItemin this scope" and "cannot find cratenextin the list of imported crates". The suggestion is confusing because it is unclear how to apply it.The error goes away if you use
Iteratordirectly:let _ = Iterator::next;produces the error one would expect: