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

Error message suggests illegal syntax for method receiver #31424

Closed
Havvy opened this issue Feb 5, 2016 · 1 comment
Closed

Error message suggests illegal syntax for method receiver #31424

Havvy opened this issue Feb 5, 2016 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Havvy
Copy link
Contributor

Havvy commented Feb 5, 2016

// 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
@durka
Copy link
Contributor

durka commented Feb 5, 2016

The argument self is of type &mut Self but it is, itself, immutable. You can't redefine self to point at somebody else. The rest of the message is nonsensical because it fails to realize that self is the specialest of special cases in terms of method signature parsing.

@Havvy Havvy changed the title Error message thinks mutable argument is immutable? Error message suggests illegal syntax for method receiver &mut Self Feb 5, 2016
@Havvy Havvy changed the title Error message suggests illegal syntax for method receiver &mut Self Error message suggests illegal syntax for method receiver Feb 5, 2016
@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 5, 2016
birkenfeld added a commit to birkenfeld/rust that referenced this issue May 10, 2016
Matching the snippet string might not be the cleanest, but matching
the AST node instead seems to end in a lot of nested `if let`s...

Fixes rust-lang#31424.
bors added a commit that referenced this issue May 10, 2016
borrowck: do not suggest to change "&mut self" to "&mut mut self"

Matching the snippet string might not be the cleanest, but matching
the AST node instead seems to end in a lot of nested `if let`s, so I
don't know what's better.

Of course it's entirely possible that there is another API altogether
that I just don't know of?

Fixes #31424.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

3 participants