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

Bad error message for when an assigned associated type does not satisfy the trait bounds #58707

Closed
LukasKalbertodt opened this issue Feb 24, 2019 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints 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.

Comments

@LukasKalbertodt
Copy link
Member

This code:

trait Bar {}

trait Foo {
    type Assoc: Bar;
}

impl Foo for () {
    type Assoc = bool;
}

Leads to (stable 1.32 and nightly 1.34):

error[E0277]: the trait bound `bool: Bar` is not satisfied
 --> src/lib.rs:7:6
  |
7 | impl Foo for () {
  |      ^^^ the trait `Bar` is not implemented for `bool`

The error is that bool does not implement Bar. I would expect that the error points to the line type Assoc = bool;, potentially with a good note. Example:

error[E0277]: the trait bound `bool: Bar` is not satisfied
 --> src/lib.rs:7:6
  |
8 |     type Assoc = bool;
  |     ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
  |
  = note: trait `Foo` requires the associated type `Assoc` to satisfy the bound `Bar`
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 24, 2019
@hellow554
Copy link
Contributor

Dup of #57663 ?

@LukasKalbertodt
Copy link
Member Author

@hellow554 Yep, looks extremely similar! Since it's not exactly the same, I copied my example to your issue to make sure both things are actually solved at some point (just in case fixing one does not fix the other). But yes, this can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints 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.
Projects
None yet
Development

No branches or pull requests

3 participants