Skip to content
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

Unhelpful help when calling associated trait function as method #103646

Closed
Noratrieb opened this issue Oct 27, 2022 · 2 comments · Fixed by #111872
Closed

Unhelpful help when calling associated trait function as method #103646

Noratrieb opened this issue Oct 27, 2022 · 2 comments · Fixed by #111872
Labels
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.

Comments

@Noratrieb
Copy link
Member

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.

@Noratrieb Noratrieb 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 Oct 27, 2022
@compiler-errors
Copy link
Member

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

@Noratrieb
Copy link
Member Author

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

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants