Skip to content

Borrow checker gets confused with a mutable pointer which should be moved #27487

Closed
@eefriedman

Description

@eefriedman
pub struct FragmentRepr(Vec<FragmentRepr>);
pub fn accepted(mut entry: &mut FragmentRepr) {
    loop {
        let FragmentRepr(ref mut discrs) = *{entry};
        entry = &mut discrs[0];
    }
}
pub fn rejected(mut entry: &mut FragmentRepr) {
    loop {
        let FragmentRepr(ref mut discrs) = *entry;
        entry = &mut discrs[0];
    }
}
fn main() {}

Rust accepts the first function, but rejects the second with "error: cannot borrow entry.0 as mutable more than once at a time". It would be nice not to be forced to insert random curly braces to convince the borrow checker that my code is correct.

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