Skip to content

Wrong suggestion for struct's type-param that is not iter::Iterator but should #46806

Closed
@lukaslueg

Description

@lukaslueg

In the following example, Rust 1.22.1 and nightly complain about T of Foobar not being iter::Iterator, which IterWrapper demands.

use std::iter;

struct IterWrapper<T:iter::Iterator> {
    iter: T
}

struct Foobar<T> {
    w: IterWrapper<T>
}

The suggestion consider adding a "where T: std::iter::Iterator" bound is correct, the main suggestion maybe try calling ".iter()" or a similar method is not applicable to this situation, though.

error[E0277]: the trait bound `T: std::iter::Iterator` is not satisfied
 --> src/main.rs:8:5
  |
8 |     w: IterWrapper<T>
  |     ^^^^^^^^^^^^^^^^^ `T` is not an iterator; maybe try calling `.iter()` or a similar method
  |
  = help: the trait `std::iter::Iterator` is not implemented for `T`
  = help: consider adding a `where T: std::iter::Iterator` bound
  = note: required by `IterWrapper`

error: aborting due to previous error

Same problem for an impl<T> Foobar<T>: Rustc suggest to call .iter() on the type-parameter, which is nonsense.

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.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