Closed
Description
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`
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: trait objects, vtable layoutArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Relevant to the compiler team, which will review and decide on the PR/issue.