Hi,
I need some help understanding why my mutable borrow is not being released.
I'm getting a compile error in my function about not being able to borrow immutable because it's being borrowed as mutable. However, my understanding is that the mutable borrow should be complete since the function does not return anything and I should be able to borrow immutably again.
Can anyone help clarify this, is my understanding correct? And if not, can you help me understand why the borrow checker thinks the borrow remains active?
Thanks!
Here is the error:
error[E0502]: cannot borrow `cf` as immutable because it is also borrowed as mutable
--> src/leema/program.rs:146:35
|
145 | cf.collect_calls(fix);
| -- mutable borrow occurs here
146 | println!("collected calls: {:?}", cf);
| ^^ immutable borrow occurs here
...
158 | }
| - mutable borrow ends here
error[E0502]: cannot borrow `cf.calls` as immutable because `cf` is also borrowed as mutable
--> src/leema/program.rs:147:18
|
145 | cf.collect_calls(fix);
| -- mutable borrow occurs here
146 | println!("collected calls: {:?}", cf);
147 | for c in cf.calls.iter() {
| ^^^^^^^^ immutable borrow occurs here
...
158 | }
| - mutable borrow ends here
And here is the code:
pub fn typecheck_current(&mut self, modname: &str, funcname: &str)
{
let inter = self.inter.get(modname).unwrap().clone();
let fix = inter.interfunc.get(funcname).unwrap();
let mut cf = CallFrame::new(modname, funcname);
cf.collect_calls(fix);
println!("collected calls: {:?}", cf);
for c in cf.calls.iter() {
println!("c: {:?}", c);
match c {
&CallOp::LocalCall(ref call_name) => {
self.deep_typecheck(modname, call_name);
}
&CallOp::ExternalCall(ref extmod, ref extfunc) => {
self.deep_typecheck(extmod, extfunc);
}
}
}
}
The surrounding code is here if that helps: https://github.com/mdg/leema/tree/reload/src/leema