Skip to content

Unhelpful help when calling associated trait function as method #103646

Closed

Description

@Noratrieb

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=895f7d2db9412f8cb60bcdd2fa05105d

trait Cat {
    fn nya() {}
}

fn uwu<T: Cat>(c: T) {
    c.nya();
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `nya` found for type parameter `T` in the current scope
 --> src/lib.rs:6:7
  |
5 | fn uwu<T: Cat>(c: T) {
  |        - method `nya` not found for this type parameter
6 |     c.nya();
  |       ^^^ this is an associated function, not a method
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `Cat`
 --> src/lib.rs:2:5
  |
2 |     fn nya() {}
  |     ^^^^^^^^
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: disambiguate the associated function for the candidate
  |
6 |     <T as Cat>::nya(c);
  |     ~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error
Compiling playground v0.0.1 (/playground)
error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): no method named `nya` found for type parameter `T` in the current scope
 --> src/lib.rs:6:7
  |
5 | fn uwu<T: Cat>(c: T) {
  |        - method `nya` not found for this type parameter
6 |     c.nya();
  |       ^^^ this is an associated function, not a method
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `Cat`
 --> src/lib.rs:2:5
  |
2 |     fn nya() {}
  |     ^^^^^^^^


For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

The error already explains the problem ("this is an associated function, not a method") and the suggestion to use a fully qualified call doesn't help. Optionally, it could even suggest calling T::nya() instead.

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 Oct 27, 2022
  2. compiler-errors commented on Oct 27, 2022

    @compiler-errors
    Contributor

    I think @clubby789 fixed this in #101990, I just need to actually re-review it and r+ it -- sorry, been quite busy.

  3. Noratrieb commented on Jan 13, 2023

    @Noratrieb
    MemberAuthor

    Said PR has been merged, but the help is still and wrong.

  4. added a commit that references this issue on May 30, 2023
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 lintsT-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