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

Incorrect hint when calling associated method as method with Deref #61411

Closed
daboross opened this issue May 31, 2019 · 0 comments · Fixed by #65145
Closed

Incorrect hint when calling associated method as method with Deref #61411

daboross opened this issue May 31, 2019 · 0 comments · Fixed by #65145
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@daboross
Copy link
Contributor

daboross commented May 31, 2019

Here's a simple example:

use std::cell::RefCell;

struct HasAssocMethod;

impl HasAssocMethod {
    fn hello() {}
}
fn main() {
    let shared_state = RefCell::new(HasAssocMethod);
    
    let state = shared_state.borrow_mut();
    
    state.hello();
}

(playground)

This outputs the following error:

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `hello` found for type `std::cell::RefMut<'_, HasAssocMethod>` in the current scope
  --> src/main.rs:13:11
   |
13 |     state.hello();
   |     ------^^^^^
   |     |     |
   |     |     this is an associated function, not a method
   |     help: use associated function syntax instead: `std::cell::RefMut<'_, HasAssocMethod>::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 `HasAssocMethod`
  --> src/main.rs:6:5
   |
6  |     fn hello() {}
   |     ^^^^^^^^^^

error: aborting due to previous error

The hint is incorrect, as std::cell::RefMut<'_, HasAssocMethod>::hello(); does not exist. Ideally the compiler should suggest HasAssocMethod::hello();.

Submitting this and #61412 as two separate issues, but I found both for the same hint.

@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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 (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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