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

Pointless suggestion for when pattern field is not mutable #53937

Closed
sunjay opened this issue Sep 4, 2018 · 2 comments
Closed

Pointless suggestion for when pattern field is not mutable #53937

sunjay opened this issue Sep 4, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@sunjay
Copy link
Member

sunjay commented Sep 4, 2018

Rust Playground

struct Foo {
    items: Vec<i32>,
}

fn main() {
    let Foo {items} = &Foo {items: vec![]};
    items.push(12);
}

This produces the error:

error[E0596]: cannot borrow immutable borrowed content `*items` as mutable
 --> src/main.rs:7:5
  |
6 |     let Foo {items} = &Foo {items: vec![]};
  |              ----- consider changing this to `items`
7 |     items.push(12);
  |     ^^^^^ cannot borrow as mutable

The suggestion "consider changing this to items" is pointless in that it won't solve the problem.

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 4, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Sep 4, 2018

This is a dupe, probably of #51244. It is definitely fixed in beta and nightly. (i believe the fix was in PR #52242.)

@pnkfelix pnkfelix closed this as completed Sep 4, 2018
@sunjay
Copy link
Member Author

sunjay commented Sep 4, 2018

Thanks!

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