mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-04 01:39:18 +00:00
Refactor mutable borrowing in move_semantics5.rs
This commit is contained in:
parent
d1a3ab5c54
commit
1a956075a0
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user