2021-06-27 01:22:46 -05:00
|
|
|
// edition:2021
|
|
|
|
|
2020-12-13 00:29:20 -06:00
|
|
|
// Test that if we deref an immutable borrow to access a Place,
|
|
|
|
// then we can't mutate the final place.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = (format!(""), format!("X2"));
|
|
|
|
let mut y = (&x, "Y");
|
|
|
|
let z = (&mut y, "Z");
|
|
|
|
|
2021-06-27 20:19:39 -05:00
|
|
|
// `x.0` is mutable but we access `x` via `*z.0.0`, which is an immutable reference and
|
2020-12-13 00:29:20 -06:00
|
|
|
// therefore can't be mutated.
|
|
|
|
let mut c = || {
|
2021-06-27 20:19:39 -05:00
|
|
|
//~^ ERROR: cannot borrow `*z.0.0` as mutable, as it is behind a `&` reference
|
2020-12-13 00:29:20 -06:00
|
|
|
z.0.0.0 = format!("X1");
|
|
|
|
};
|
|
|
|
|
|
|
|
c();
|
|
|
|
}
|