Skip to content

1.17 nightly Compiler suggests wrong syntax mut mut var  #40823

Closed
@yasammez

Description

@yasammez

When trying to compile

fn main() {
    let mut buf = &[1, 2, 3, 4];
    let mut dst = &[0, 0, 0, 0];
    for (x, y) in buf.iter_mut().zip(dst) {
        *y = *x
    }
}

the compiler rustc 1.17.0-nightly (3da4023 2017-03-24) throws an error together with a helpful suggestion

error: cannot borrow immutable borrowed content `*buf` as mutable
 --> <anon>:4:19
  |
2 |     let mut buf = &[1, 2, 3, 4];
  |         ------- consider changing this to `mut mut buf`
3 |     let mut dst = &[0, 0, 0, 0];
4 |     for (x, y) in buf.iter_mut().zip(dst) {
  |                   ^^^ cannot borrow as mutable

Here, the mut mut buf is obviously very very wrong. The stable and beta compilers don't suffer from this issue (they just provide no „consider …“ message at all).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions