Skip to content

Commit d7024d8

Browse files
committed
move_semantics4: Avoid using the dereference operator
1 parent 59d6b85 commit d7024d8

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

exercises/06_move_semantics/move_semantics4.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ mod tests {
88
// Don't add, change or remove any line.
99
#[test]
1010
fn move_semantics4() {
11-
let mut x = 100;
11+
let mut x = Vec::new();
1212
let y = &mut x;
1313
let z = &mut x;
14-
*y += 100;
15-
*z += 1000;
16-
assert_eq!(x, 1200);
14+
y.push(42);
15+
z.push(13);
16+
assert_eq!(x, [42, 13]);
1717
}
1818
}

solutions/06_move_semantics/move_semantics4.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ mod tests {
77
// TODO: Fix the compiler errors only by reordering the lines in the test.
88
// Don't add, change or remove any line.
99
#[test]
10-
fn move_semantics5() {
11-
let mut x = 100;
10+
fn move_semantics4() {
11+
let mut x = Vec::new();
1212
let y = &mut x;
1313
// `y` used here.
14-
*y += 100;
14+
y.push(42);
1515
// The mutable reference `y` is not used anymore,
1616
// therefore a new reference can be created.
1717
let z = &mut x;
18-
*z += 1000;
19-
assert_eq!(x, 1200);
18+
z.push(13);
19+
assert_eq!(x, [42, 13]);
2020
}
2121
}

0 commit comments

Comments
 (0)