Skip to content

Wrong mut &mut self suggestion #34126

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

Closed
therustmonk opened this issue Jun 6, 2016 · 4 comments
Closed

Wrong mut &mut self suggestion #34126

therustmonk opened this issue Jun 6, 2016 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@therustmonk
Copy link
Contributor

therustmonk commented Jun 6, 2016

I've found wrong suggestion with the following code (play):

struct Z { }

impl Z {
  fn run(&self, z: &mut Z) { }
  fn start(&mut self) { self.run(&mut self); }
}

fn main() {
  let mut z = Z {};
  z.start();
}

stable release prints like in #31424:

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

but nightly takes suggestion to use mut &mut self:

error: cannot borrow immutable argument `self` as mutable
 --> <anon>:8:19
7 |>   fn start(&mut self) {
  |>            --------- use `mut &mut self` here to make mutable
8 |>     self.run(&mut self);
  |>                   ^^^^ cannot borrow mutably

error: aborting due to previous error
playpen: application terminated with error code 101
@durka
Copy link
Contributor

durka commented Jun 6, 2016

cc @birkenfeld

@birkenfeld
Copy link
Contributor

This is due to the change in how self arguments are represented. Now we can probably properly check, I'll have a look.

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 7, 2016
@alexandermerritt
Copy link
Contributor

Possibly related? #34337

bors added a commit that referenced this issue Nov 12, 2016
Fix invalid "ref mut mut" sugestion

Change output from:

```nocode
error: cannot borrow immutable local variable `x` as mutable
  --> <anon>:12:23
   |
11 |         TestEnum::Item(ref mut x) => {
   |                        --------- use `ref mut mut x` here to make mutable
12 |             test(&mut x);
   |                       ^ cannot borrow mutably
```

to

```nocode
error: cannot borrow immutable local variable `x` as mutable
  --> <anon>:12:23
   |
12 |             test(&mut x);
   |                       ^
   |                       |
   |                       cannot reborrow mutably
   |                       try removing `&mut` here
```
Fixes #37139, #34337, #34126
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@nikomatsakis
Copy link
Contributor

Fixed by #37531 it seems

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

7 participants