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

Hint suggesting using associated method instead of method uses incorrect syntax for generic method access #61412

Closed
daboross opened this issue May 31, 2019 · 0 comments · Fixed by #65145
Labels
A-associated-items Area: Associated items such as associated types and consts. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@daboross
Copy link
Contributor

daboross commented May 31, 2019

Consider this example:

struct GenericAssocMethod<T>(T);
impl<T> GenericAssocMethod<T> {
    fn default_hello() {}
}

fn main() {
    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.

@daboross daboross 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 May 31, 2019
@estebank estebank added A-associated-items Area: Associated items such as associated types and consts. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels May 31, 2019
@estebank estebank added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Oct 5, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 8, 2019
…=varkor

When suggesting assoc function with type params, include turbofish

Fix rust-lang#61412, fix rust-lang#61411.
@bors bors closed this as completed in 58bfe3b Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants