I've been trying to understand how borrows work more deeply and I've run into a simple scenario that I can't make head nor tail of. It involves two snippets.
let mut a = 1; let b = &mut a; let c = &*b; let d = *b;
let mut a = 1; let b = &mut a; let c = &a; let d = *b;
The only difference is on the
let c = ... line. The first one compiles and the second one doesn't. I think I understand the second one (mutable + immutable borrow is disallowed). My questions:
Why does the first one work; what difference does
- Is this explained somewhere in the documentation?
Full disclosure: I came here after trying to read about stacked borrows and it's possible the answer is somewhere in there, but I'm very far from grokking all the rules.