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