Skip to content

"maybe try calling .iter()" on missing trait implementation #55159

Closed
@TheSilvus

Description

@TheSilvus

Implementing a trait that requires an iterator trait on a struct without implementing the iterator itself leads to an irrelevant error message.

fn main() {}

trait A: Iterator<Item=i32> {}

struct B {}
impl A for B {}

Error message:

error[E0277]: the trait bound `B: std::iter::Iterator` is not satisfied
 --> src/main.rs:6:6
  |
6 | impl A for B {}
  |      ^ `B` is not an iterator; maybe try calling `.iter()` or a similar method
  |
  = help: the trait `std::iter::Iterator` is not implemented for `B`

Actually implementing the iterator fixes the error.

I tried it on the Rust Playground, so I should have used the newest versions: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=a5a597c2a8d0fa4769ff30dca58443c0 . I ran it on all three channels.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions