-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
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.
Description
Code
struct S;
struct T;
// error[E0229]: associated type bindings are not allowed here
// --> src/lib.rs:9:26
// |
//9 | impl std::cmp::PartialEq<Rhs = T> for S {
// | ^^^^^^^ associated type not allowed here
impl std::cmp::PartialEq<Rhs = T> for S {
fn eq(&self, _other: &T) -> bool {
true
}
}
// Works
/*impl std::cmp::PartialEq<T> for S {
fn eq(&self, _other: &T) -> bool {
true
}
}*/
Current output
error[E0229]: associated type bindings are not allowed here
9 | impl std::cmp::PartialEq<Rhs = T> for S {
| ^^^^^^^ associated type not allowed here
Desired output
error[E0229]: associated type bindings are not allowed here
9 | impl std::cmp::PartialEq<Rhs = T> for S {
| ^^^^^^^ associated type not allowed here,
| `std::cmp::PartialEq` has a generic parameter, not an associated type, so the `Rhs =` syntax is not appropriate to use here.
| Did you mean `impl std::cmp::PartialEq<T>`?
Rationale and extra context
I have been writing Rust for years and still get the syntax for trait generic type params and trait associated types mixed up. In this case, I copy-and-pasted the trait signature from the documentation and put impl
in front of it.
In my mind, I never had any intent to bind an associated type. My goal was to impl PartialEq
.
I now see my mistake, but in this case the error messages did not help me get there and perhaps could be improved.
Other cases
No response
Rust Version
1.76.0 Stable
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=64a8a896091da005a5a8ddfce5b5ea77
Anything else?
No response
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.