Skip to content

Commit f9ca8d7

Browse files
committed
Question improvements
1 parent 22212a7 commit f9ca8d7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

questions/q250.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ question: |-
2121
requires_send(arc_data);
2222
requires_send(mutex_data);
2323
requires_sync(refcell_data);
24+
requires_send(rc_data);
2425
}
2526
```
2627
@@ -30,7 +31,7 @@ answers:
3031
- Only the `requires_send(rc_data)` line
3132
- Both `requires_send(rc_data)` and `requires_sync(refcell_data)` lines
3233
- All function calls work without errors
33-
correct_answer: 0
34+
correct_answer: 2
3435
expected_output:
3536
- error[E0277]
3637
- cannot be shared between threads safely
@@ -59,11 +60,10 @@ explanation: |-
5960
- `Mutex<T>` is both `Send` and `Sync` (when `T: Send`) because it provides
6061
thread-safe interior mutability through locking.
6162
62-
In the code, `rc_data` is created but never used in a function call, so it
63-
doesn't cause an error. The calls `requires_send(arc_data)` and
64-
`requires_send(mutex_data)` both succeed because `Arc` and `Mutex` implement
65-
`Send`. However, `requires_sync(refcell_data)` fails to compile because
66-
`RefCell` does not implement `Sync`.
63+
The calls `requires_send(arc_data)` and `requires_send(mutex_data)` both succeed
64+
because `Arc` and `Mutex` implement `Send`. However, `requires_sync(refcell_data)`
65+
and `requires_send(rc_data)` both fail to compile. The former fails because `RefCell`
66+
does not implement `Sync`, and the latter because `Rc` does not implement `Send`.
6767
6868
The key takeaway is that `RefCell` provides interior mutability for
6969
single-threaded scenarios, while `Mutex` provides thread-safe interior

questions/q300.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ answers:
2121
- 1 5
2222
- 11 10
2323
- 2 5
24-
- 12 5
24+
- Code fails to compile because `map` is mutably borrowed twice
2525
correct_answer: 1
2626
expected_output:
2727
- 11 10

0 commit comments

Comments
 (0)