Skip to content

Confusing error caused by double peojection in trait supertraits #102185

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

Open
WaffleLapkin opened this issue Sep 23, 2022 · 3 comments
Open

Confusing error caused by double peojection in trait supertraits #102185

WaffleLapkin opened this issue Sep 23, 2022 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Sep 23, 2022

Given the following code: (play)

fn f<T>(_: impl A<X = T>) {}

trait A: C<Z = <<Self as A>::X as B>::Y> {
    type X: B;
}

trait B {
    type Y;
}

trait C {
    type Z;
}

The current output is:

error[E0277]: the trait bound `T: B` is not satisfied
 --> src/lib.rs:1:1
  |
1 | fn f<T>(_: impl A<X = T>) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `B` is not implemented for `T`
  |
help: consider restricting type parameter `T`
  |
1 | fn f<T: B>(_: impl A<X = T>) {}
  |       +++

error[E0277]: the trait bound `T: B` is not satisfied
 --> src/lib.rs:1:17
  |
1 | fn f<T>(_: impl A<X = T>) {}
  |                 ^^^^^^^^ the trait `B` is not implemented for `T`
  |
help: consider restricting type parameter `T`
  |
1 | fn f<T: B>(_: impl A<X = T>) {}
  |       +++

This is confusing because it seems like this error is caused by type X: B in the trait, but actually it's caused by X as B in the supertraits, if your remove X as B the code compiles (as it should in any case, IMO!).

Ideally the code would compile or at least the output should look like:

error[E0277]: the trait bound `T: B` is not satisfied
 --> src/lib.rs:1:1
  |
1 | fn f<T>(_: impl A<X = T>) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `B` is not implemented for `T`
  |
help: consider restricting type parameter `T`
  |
1 | fn f<T: B>(_: impl A<X = T>) {}
  |       +++
note: required because of this
  |
3 | trait A: C<Z = <<Self as A>::X as B>::Y> {
  |                  ^^^^^^^^^^^^^^^^^^

@rustbot label +D-confusing

@WaffleLapkin WaffleLapkin added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 23, 2022
@rustbot rustbot added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Sep 23, 2022
@SparrowLii
Copy link
Member

@rustbot claim

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Oct 4, 2023
@estebank
Copy link
Contributor

Triage: no change.

@WaffleLapkin
Copy link
Member Author

@SparrowLii I've unassigned you, since #102502 was closed. Feel free to reclaim, in case you are working on another fix.

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 D-confusing Diagnostics: Confusing error or lint that should be reworked. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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

5 participants