Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show generic bounds in E0046 #50734

Closed
JustAPerson opened this issue May 14, 2018 · 3 comments
Closed

Show generic bounds in E0046 #50734

JustAPerson opened this issue May 14, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@JustAPerson
Copy link
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.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system labels May 14, 2018
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Jan 30, 2020
@estebank
Copy link
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
Copy link
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!() }`

bors added a commit that referenced this issue Feb 9, 2020
When suggesting associated fn with type parameters, include in the structured suggestion

Address #50734.

```
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `baz`
  --> file.rs:14:1
   |
14 | impl TraitA<()> for S {
   | ^^^^^^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `baz` in implementation
   |
   = help: implement the missing item: `fn foo<T>(_: T) -> Self where T: TraitB, TraitB::Item = A { unimplemented!() }`
   = help: implement the missing item: `fn bar<T>(_: T) -> Self { unimplemented!() }`
   = help: implement the missing item: `fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: std::marker::Copy { unimplemented!() }`
```

It doesn't work well for associated types with `ty::Predicate::Projection`s as we need to resugar `T: Trait, Trait::Assoc = K` → `T: Trait<Assoc = K>`.
@estebank
Copy link
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
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants