I seem to have got myself confused over this program:
fn main() {
let mut x = Box::new(0);
let mut y = Box::new(&mut x);
y = Box::new({*y});
}
The error message on the playground is:
error[E0506]: cannot assign to `y` because it is borrowed
--> src/main.rs:4:3
|
4 | y = Box::new(*y);
| ^ -- borrow of `y` occurs here
| |
| assignment to borrowed `y` occurs here
| borrow later used here
Somehow this doesn't make sense to me since I'm not borrowing y
at all! In fact, I don't see a problem with this program. Note it is the same if {*y}
becomes *y
.