- 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.