Skip to content

Suggest mutable self receiver if self is used mutably聽#101145

Description

@carbotaniuman

Given the following code:

struct Lexer {
    parse_header: bool,
}
impl Lexer {
    fn set_include_mode(parse_header: bool) {
        self.parse_header = parse_header;
    }
}
<code>

The current output is:

error[E0424]: expected value, found module `self`
  --> src/preprocess/lex.rs:18:9
   |
17 |     fn set_include_mode(parse_header: bool) {
   |        ---------------- this function doesn't have a `self` parameter
18 |         self.parse_header = parse_header;
   |         ^^^^ `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
   |
17 |     fn set_include_mode(&self, parse_header: bool) {
   |                         ++++++

Ideally the output should look like:

error[E0424]: expected value, found module `self`
  --> src/preprocess/lex.rs:18:9
   |
17 |     fn set_include_mode(parse_header: bool) {
   |        ---------------- this function doesn't have a `self` parameter
18 |         self.parse_header = parse_header;
   |         ^^^^ `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
   |
17 |     fn set_include_mode(&mut self, parse_header: bool) {
   |                         +++++++++

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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