Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lilyball opened this issue Apr 20, 2013 · 2 comments

Comments

@lilyball
Copy link
Contributor

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.

@lilyball
Copy link
Contributor Author

The only way I could figure out how to accomplish what I wanted was to stuff the map into a @mut box. Surely that shouldn't be necessary.

@nikomatsakis
Copy link
Contributor

this is due to the lack of flow-sensitivity in the borrow checker. hopefully this will be fixed soon. dup of #5074

flip1995 added a commit to flip1995/rust that referenced this issue Aug 29, 2020
[beta] Backport: Re-enable len_zero for ranges now that `is_empty` is stable on them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants