Skip to content

Goofy suggestion when trying to use a raw ptr receiver and also the self keyword in the body #128042

Closed
@saethlin

Description

@saethlin

I tried this code:

struct Thing {
    state: u8,
}

impl Thing {
    fn oof(*mut Self) {
        self.state = 1;
    }
}

I get this diagnostic, which is all good until it tries to construct a suggestion:

error[E0424]: expected value, found module `self`
 --> src/lib.rs:7:9
  |
6 |     fn oof(*mut Self) {
  |        --- this function doesn't have a `self` parameter
7 |         self.state = 1;
  |         ^^^^ `self` value is a keyword only available in methods with a `self` parameter
  |
help: add a `self` receiver parameter to make the associated `fn` a method
  |
6 |     fn oof&self, (*mut Self) {
  |           ++++++

This suggestion has behaved like this since it was added in 1.47.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions