Skip to content

Unexpected error: loan of mutable local variable as mutable conflicts with prior loan #5982

Closed
@lilyball

Description

@lilyball

I have some code that looks like

let mut map : LinearMap<~[u8], int> = LinearMap::new();

for split_vec(text, 16).each |&block| {
    match map.find_mut(&block) {
        None => { map.insert(block, 0); }
        Some(x) => { *x += 1; }
    }
}

(split_vec returns a ~[~[T]])

Unfortunately the compiler complains about

foo.rc:46:13: 46:16 error: loan of mutable local variable as mutable conflicts with prior loan
foo.rc:46             None => { map.insert(block, 0); }
                                ^~~
foo.rc:45:8: 45:11 note: prior loan as mutable granted here
foo.rc:45         match map.find_mut(&block) {
                        ^~~

I can't figure out why calling two methods that both take &mut self is a problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions