Skip to content

Show generic bounds in E0046  #50734

Closed
Closed
@JustAPerson

Description

@JustAPerson

Consider:

use std::iter::FromIterator;
struct X;
impl FromIterator<()> for X {
}

which causes the following error on stable and nightly:

error[E0046]: not all trait items implemented, missing: `from_iter`
 --> src/main.rs:3:1
  |
3 | impl FromIterator<()> for X {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_iter` in implementation
  |
  = note: `from_iter` from trait: `fn(T) -> Self`

It would be super helpful to print the other relevant bounds for this method:

pub trait FromIterator<A> {
    fn from_iter<T>(iter: T) -> Self
    where
        T: IntoIterator<Item = A>;
}

Just trying to add a partial definition fn from_iter<I>(i: I) -> Self { Self } will be accepted without any bound on I. Of course you can't really do anything with it yet. Thus it would be pleasant to remind the user what bound they probably need.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.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