-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
compiler-errors commentedon Oct 27, 2022
I think @clubby789 fixed this in #101990, I just need to actually re-review it and r+ it -- sorry, been quite busy.
Noratrieb commentedon Jan 13, 2023
Said PR has been merged, but the help is still and wrong.
static_candidates
before report #111872Rollup merge of rust-lang#111872 - bvanjoi:fix-103646, r=cjgillot