Open
Description
Given
fn f(mut p: &mut i32) {
let mut number = 111;
p = &mut number;
*p = 2;
println!("{}", *p);
}
we currently emit
error[E0597]: `number` does not live long enough
--> f44.rs:4:9
|
1 | fn f(mut p: &mut i32) {
| - let's call the lifetime of this reference `'1`
...
4 | p = &mut number;
| ----^^^^^^^^^^^
| | |
| | borrowed value does not live long enough
| assignment requires that `number` is borrowed for `'1`
...
8 | }
| - `number` dropped here while still borrowed
but it could be more informative:
error[E0597]: `number` does not live long enough
--> f44.rs:4:9
|
1 | fn f(mut p: &mut i32) {
| - let's call the lifetime of this reference `'1`
...
3 | let mut number = 111;
| ----- --- this value is assigned to `number` and lives as long as `f`
| |
| this binding only lives for the duration of function `f` and gets dropped at the function
4 | p = &mut number;
| ----^^^^^^^^^^^
| | |
| | borrowed value does not live long enough
| this assignment to `p` will outlive `f` because it is a `&mut i32` owned by the caller's scope
...
8 | }
| - `number` dropped here while still borrowed