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

Contradictory error message: trait is simultaneously implemented and not #105048

Open
Kyuuhachi opened this issue Nov 29, 2022 · 2 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kyuuhachi
Copy link
Contributor

The following code gives somewhat contradictory error message:

trait A {}
struct B;

impl A for B where B: A {}
impl A for B where B: A {}

fn main() {
    let a: &dyn A = &B;
}
error[E0277]: the trait bound `B: A` is not satisfied
 --> src/lib.rs:4:20
  |
4 | impl A for B where B: A {}
  |                    ^^^^ the trait `A` is not implemented for `B`
  |
  = help: the trait `A` is implemented for `B`
  = help: see issue #48214

^^^^ the trait `A` is not implemented for `B`
help: the trait `A` is implemented for `B`

???

Including only one of the impl lines produces a more reasonable overflow evaluating the requirement `B: A` instead.

This happens both on stable 1.65.0, beta 1.66.0-beta.2 (2022-11-20 004070), and nightly 1.67.0-nightly (2022-11-28 2585bc).

Nightly suggests adding #![feature(trivial_bounds)], but the contradictory error message still exists with that (however pointed at the dyn rather than the impls).

@Kyuuhachi Kyuuhachi added the C-bug Category: This is a bug. label Nov 29, 2022
@Kyuuhachi
Copy link
Contributor Author

Sorry, this should be tagged diagnostic, not bug. Don't know how to change that.

@lukas-code
Copy link
Contributor

@rustbot label -C-bug +A-diagnostics +A-traits +T-compiler +D-confusing

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Nov 29, 2022
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-traits Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. 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