From 6400736142172ea0cd64e742bf43cd119e24f02a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 27 Jun 2022 15:49:59 -0700 Subject: [PATCH] Implement `Send` and `Sync` for `ThinBox` Just like `Box`, `ThinBox` owns its data on the heap, so it should implement `Send` and `Sync` when `T` does. --- library/alloc/src/boxed/thin.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index 807c035fdbd0d..203e5dff0c77f 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -33,6 +33,14 @@ pub struct ThinBox { _marker: PhantomData, } +/// `ThinBox` is `Send` if `T` is `Send` because the data is owned. +#[unstable(feature = "thin_box", issue = "92791")] +unsafe impl Send for ThinBox {} + +/// `ThinBox` is `Sync` if `T` is `Sync` because the data is owned. +#[unstable(feature = "thin_box", issue = "92791")] +unsafe impl Sync for ThinBox {} + #[unstable(feature = "thin_box", issue = "92791")] impl ThinBox { /// Moves a type to the heap with its `Metadata` stored in the heap allocation instead of on