Refactor mutable borrowing in move_semantics5.rs

This commit is contained in:
Rock070 2023-12-17 16:25:54 +08:00
parent d1a3ab5c54
commit 1a956075a0

View File

@ -5,15 +5,19 @@
//
// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand
// for a hint.
// I AM NOT DONE
// [[NOTE]] 使用作用域讓可變借用的生命週期提早結束
#[test]
fn main() {
let mut x = 100;
let y = &mut x;
let z = &mut x;
*y += 100;
*z += 1000;
let mut x = 100;
{
let y = &mut x;
*y += 100;
}
{
let z = &mut x;
*z += 1000;
}
assert_eq!(x, 1200);
}