-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
Description
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.