From fe89a1fe15c0464470d80c7c85761db37aa83762 Mon Sep 17 00:00:00 2001 From: Claudia Meadows Date: Thu, 12 Jan 2023 18:22:17 -0800 Subject: [PATCH] [core] Fix a soundness hole in `core::sync::Exclusive` Just like `Mutex` is only `Sync` if `T` is `Send`, `Exclusive` should contain the same constraints. --- library/core/src/sync/exclusive.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index 301ad41c96634..101b83dc0c6a3 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -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(); /// } /// }); /// ``` @@ -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(); /// }) /// }); /// ``` @@ -87,7 +85,7 @@ pub struct Exclusive { // See `Exclusive`'s docs for justification. #[unstable(feature = "exclusive_wrapper", issue = "98407")] -unsafe impl Sync for Exclusive {} +unsafe impl Sync for Exclusive {} #[unstable(feature = "exclusive_wrapper", issue = "98407")] impl fmt::Debug for Exclusive {