Closed
Description
This code:
fn f(x: &mut u32) { }
fn main() {
let x = 3;
f(&mut x);
}
produces a helpful error message:
error: cannot borrow immutable local variable `x` as mutable
--> <anon>:5:12
|
4 | let x = 3;
| - use `mut x` here to make mutable
5 | f(&mut x);
| ^ cannot borrow mutably
But the analogous code using a Box
:
fn f(x: &mut u32) { }
fn main() {
let x = Box::new(3);
f(&mut *x);
}
gives an error which doesn't point at the binding x
:
error: cannot borrow immutable `Box` content `*x` as mutable
--> <anon>:5:12
|
5 | f(&mut *x);
| ^^