Skip to content

Error message suggests illegal syntax for method receiver #31424

Closed
@Havvy

Description

@Havvy
// Playpen Link: http://is.gd/2baYh8
struct Struct;

impl Struct {
    fn foo(&mut self) {
        (&mut self).bar();
    }

    fn bar(&mut self) {}
}

fn main () {}

Output:

<anon>:5:15: 5:19 error: cannot borrow immutable argument `self` as mutable
<anon>:5         (&mut self).bar();
                       ^~~~
<anon>:4:17: 4:21 help: to make the argument mutable, use `mut` as shown:
<anon>:      fn foo(&mut mut self) {
error: aborting due to previous error
playpen: application terminated with error code 101

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions