Skip to content

Show generic bounds in E0046  #50734

@JustAPerson

Description

@JustAPerson
Contributor

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.

Activity

added
C-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.
on Oct 2, 2018
added
D-papercutDiagnostics: An error or lint that needs small tweaks.
on Jan 30, 2020
estebank

estebank commented on Jan 30, 2020

@estebank
Contributor

Current output, no real change other than using a copy/paste-able signature:

error[E0046]: not all trait items implemented, missing: `from_iter`
 --> src/lib.rs:3:1
  |
3 | impl FromIterator<()> for X {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_iter` in implementation
  |
  = help: implement the missing item: `fn from_iter(_: T) -> Self { unimplemented!() }`
estebank

estebank commented on Jan 31, 2020

@estebank
Contributor

The output from #68689 is not perfect because it uses incorrect syntax, but gets us closer to the correct output:

error[E0046]: not all trait items implemented, missing: `from_iter`
  --> $DIR/missing-assoc-fn.rs:19:1
   |
LL | impl FromIterator<()> for X {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_iter` in implementation
   |
   = help: implement the missing item: `fn from_iter<T>(_: T) -> Self where T: std::iter::IntoIterator, std::iter::IntoIterator::Item = A { unimplemented!() }`
added a commit that references this issue on Feb 9, 2020
estebank

estebank commented on Oct 17, 2023

@estebank
Contributor

Current output:

error[E0046]: not all trait items implemented, missing: `from_iter`
 --> src/lib.rs:3:1
  |
3 | impl FromIterator<()> for X {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_iter` in implementation
  |
  = help: implement the missing item: `fn from_iter<T: IntoIterator<Item = ()>>(_: T) -> Self { todo!() }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @JustAPerson@estebank@XAMPPRocky@fmease

        Issue actions

          Show generic bounds in E0046 · Issue #50734 · rust-lang/rust