-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.
Description
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();
}
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.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.