From 1a956075a0156c8252817bf676e5210154757489 Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sun, 17 Dec 2023 16:25:54 +0800 Subject: [PATCH] Refactor mutable borrowing in move_semantics5.rs --- exercises/06_move_semantics/move_semantics5.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/exercises/06_move_semantics/move_semantics5.rs b/exercises/06_move_semantics/move_semantics5.rs index 267bdccc..6147a525 100644 --- a/exercises/06_move_semantics/move_semantics5.rs +++ b/exercises/06_move_semantics/move_semantics5.rs @@ -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); }