Skip to content

In impl trait, E0229 "associated type bindings are not allowed here" could suggest a solution or at least be less confusing #122162

Closed

Description

@marshrayms

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 8, 2024
  2. added
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    on Mar 8, 2024
  3. added a commit that references this issue on Apr 23, 2024
    68939f7
  4. added a commit that references this issue on Apr 23, 2024
    00ff515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions