Skip to content

Commit

Permalink
[core] Fix a soundness hole in core::sync::Exclusive
Browse files Browse the repository at this point in the history
Just like `Mutex<T>` is only `Sync` if `T` is `Send`, `Exclusive<T>` should contain the same constraints.
  • Loading branch information
dead-claudia committed Jan 13, 2023
1 parent 86ad69d commit fe89a1f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions library/core/src/sync/exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ use core::task::{Context, Poll};
/// assert_sync(State {
/// future: async {
/// let cell = Cell::new(1);
/// let cell_ref = &cell;
/// other().await;
/// let value = cell_ref.get();
/// let value = cell.get();
/// }
/// });
/// ```
Expand All @@ -55,10 +54,9 @@ use core::task::{Context, Poll};
///
/// assert_sync(State {
/// future: Exclusive::new(async {
/// let cell = Cell::new(1);
/// let cell_ref = &cell;
/// let mut cell = Cell::new(1);
/// other().await;
/// let value = cell_ref.get();
/// let value = cell.get();
/// })
/// });
/// ```
Expand Down Expand Up @@ -87,7 +85,7 @@ pub struct Exclusive<T: ?Sized> {

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

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

0 comments on commit fe89a1f

Please sign in to comment.