Skip to content

Pointless suggestion for when pattern field is not mutable #53937

Closed
@sunjay

Description

@sunjay

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.

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