mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-05 02:09: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
|
// 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user