Skip to content

Commit fe89a1f

Browse files
committed
[core] Fix a soundness hole in core::sync::Exclusive
Just like `Mutex<T>` is only `Sync` if `T` is `Send`, `Exclusive<T>` should contain the same constraints.
1 parent 86ad69d commit fe89a1f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

library/core/src/sync/exclusive.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ use core::task::{Context, Poll};
3333
/// assert_sync(State {
3434
/// future: async {
3535
/// let cell = Cell::new(1);
36-
/// let cell_ref = &cell;
3736
/// other().await;
38-
/// let value = cell_ref.get();
37+
/// let value = cell.get();
3938
/// }
4039
/// });
4140
/// ```
@@ -55,10 +54,9 @@ use core::task::{Context, Poll};
5554
///
5655
/// assert_sync(State {
5756
/// future: Exclusive::new(async {
58-
/// let cell = Cell::new(1);
59-
/// let cell_ref = &cell;
57+
/// let mut cell = Cell::new(1);
6058
/// other().await;
61-
/// let value = cell_ref.get();
59+
/// let value = cell.get();
6260
/// })
6361
/// });
6462
/// ```
@@ -87,7 +85,7 @@ pub struct Exclusive<T: ?Sized> {
8785

8886
// See `Exclusive`'s docs for justification.
8987
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
90-
unsafe impl<T: ?Sized> Sync for Exclusive<T> {}
88+
unsafe impl<T: ?Sized + Send> Sync for Exclusive<T> {}
9189

9290
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
9391
impl<T: ?Sized> fmt::Debug for Exclusive<T> {

0 commit comments

Comments
 (0)