Skip to content

E0191: "help: specify the associated type" suggested where this would be wrong #91997

Closed
@jendrikw

Description

@jendrikw

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

A-diagnosticsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions