You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hint suggesting using associated method instead of method uses incorrect syntax for generic method access #61412
A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
structGenericAssocMethod<T>(T);impl<T>GenericAssocMethod<T>{fndefault_hello(){}}fnmain(){let x = GenericAssocMethod(33i32);
x.default_hello();}
This errors with the following error:
error[E0599]: no method named `default_hello` found for type `GenericAssocMethod<i32>` in the current scope
--> src/main.rs:8:7
|
1 | struct GenericAssocMethod<T>(T);
| -------------------------------- method `default_hello` not found for this
...
8 | x.default_hello();
| --^^^^^^^^^^^^^
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `GenericAssocMethod<i32>::default_hello`
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `GenericAssocMethod<_>`
--> src/main.rs:3:5
|
3 | fn default_hello() {}
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
The problem is that if I follow the hint exactly, I end up with GenericAssocMethod<i32>::default_hello();, which is invalid rust syntax.
Ideally, I believe suggesting GenericAssocMethod::<i32>::default_hello would be more beneficial.
Submitting this and #61411 as two separate issues, but I found both for the same hint.
changed the title [-]Hint suggesting using associated method instead of method uses incorrect syntax for generic types[/-][+]Hint suggesting using associated method instead of method uses incorrect syntax for generic method access[/+]on May 31, 2019
A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
Activity
[-]Hint suggesting using associated method instead of method uses incorrect syntax for generic types[/-][+]Hint suggesting using associated method instead of method uses incorrect syntax for generic method access[/+]Rollup merge of rust-lang#65145 - estebank:turbofish-assoc-fn-call, r…
Rollup merge of rust-lang#65145 - estebank:turbofish-assoc-fn-call, r…