Skip to content

Destructuring boxes into multiple mutable references seems broken #30104

Closed
@ben0x539

Description

@ben0x539

This fails with "cannot mutably borrow more than once" errors

fn push(mut node: Box<(i32, i32)>) {
    let (ref mut left, ref mut right) = *node;
}

Same here:

fn push(mut node: Box<(i32, i32)>) {
    let box (ref mut left, ref mut right) = node;
}

This works:

fn push(mut node: Box<(i32, i32)>) {
    let (ref mut left, ref mut right) = *&mut *node;
}

This also works:

fn push(node: &mut (i32, i32)) {
    let (ref mut left, ref mut right) = *node;
}

Same behavior with structs instead of tuples. Boxes are weird, destructuring into mutable borrows is weird, so I have no idea what is going on there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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