Skip to content

Don't suggest calling .iter() when unsatified Iterator bound does not originate from an expression #50773

Closed
@kennytm

Description

@kennytm

Demo:

struct S<I: Iterator>(I);
struct T(S<u8>);
fn main() {}

This will cause the strange suggestion:

error[E0277]: the trait bound `u8: std::iter::Iterator` is not satisfied
 --> src/main.rs:2:10
  |
2 | struct T(S<u8>);
  |          ^^^^^^ `u8` is not an iterator; maybe try calling `.iter()` or a similar method
  |
  = help: the trait `std::iter::Iterator` is not implemented for `u8`
note: required by `S`
 --> src/main.rs:1:1
  |
1 | struct S<I: Iterator>(I);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^

There is no place to "call .iter()". That suggestion should be removed here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions