Which borrow is exactly the issue here?
⚓ Rust 📅 2026-01-02 👤 surdeus 👁️ 1From what I understand, the following code is problematic because root is borrowed both mutably and immutably inside a loop. However, the error message is a bit more cryptic, because it seems to also involve the unrelated variable scene.
let mut root = Root::new(device, queue, surface, &config, playback);
let mut scene = Scene { instances: vec![] };
let mut hud = Hud {};
loop {
update(&mut root);
sync(&root, &mut scene, &mut hud);
render(&root, &scene, &hud);
}
Here is the diagnostic.
error[E0502]: cannot borrow `root` as mutable because it is also borrowed as immutable
--> src\main.rs:62:22
|
62 | update::update(&mut root);
| ^^^^^^^^^ mutable borrow occurs here
63 | sync::sync(&root, &mut scene, &mut hud);
| ----- ---------- immutable borrow later used here
| |
| immutable borrow occurs here
Is the checker really complaining about scene? Why? What's the deal with scene?
Thanks!
7 posts - 4 participants
🏷️ Rust_feed