대여한 값이 사용되기 전에 값이 변경되면 에러가 발생한다.
fn main() {
let mut bag = MyBag { item: 32i32 };
let b = &mut bag;
bag.item = 13;// error
b.item = 5;
println!("{}", bag.item);
}
--> src\main.rs:12:5
|
11 | let b = &mut bag;
| -------- borrow of `bag.item` occurs here
12 | bag.item = 13;
| ^^^^^^^^^^^^^ assignment to borrowed `bag.item` occurs here
13 | b.item = 5;
| ---------- borrow later used here