Skip to content

Compiler error could suggest using an associated type for e.g. Iterator<T> #20977

Closed
@tomjakubowski

Description

@tomjakubowski

If you accidentally write a bound like:

pub struct Foo<T, I: Iterator<T>> { /* ... */ }

The error message is:

err.rs:3:22: 3:33 error: wrong number of type arguments: expected 0, found 1
err.rs:3 pub struct Foo<T, I: Iterator<T>> { x: I }
                              ^~~~~~~~~~~

The compiler could be more helpful in these cases where a trait takes 0 arguments but has an associated type and suggest something like: Iterator has an associated type. Did you mean: I: Iterator<Item=T>?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-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.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions