Skip to content

Slice pattern incorrectly report double borrow #37302

Closed
@Popog

Description

@Popog

Seems you can work around issue by throwing enough &mut/& and * at the problem.

let mut v: [i32;2] = [1; 2];

let [ref mut _a, ref mut _b] = v; // Double borrow error
let [ref mut _a, ref mut _b] = *&mut v;
let &mut [ref mut _a, ref mut _b] = &mut v;

let rv = &mut v;
let &mut [ref mut _a, ref mut _b] = rv; // Double borrow error
let &mut [ref mut _a, ref mut _b] = &mut* rv;

let [ref mut _a, ref mut _b] = *rv; // Double borrow error
let [ref mut _a, ref mut _b] = *&mut *rv;

Value case has a similar issue that might be related (haven't found a workaround yet):

struct NoCopy;
let v: [NoCopy;2] = [NoCopy, NoCopy];
let [_a, _b] = v; // Value used after move

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions