From c155d5149fe49736cfb5b24eaa1c854b836019f3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 13 Apr 2023 16:45:07 +0000 Subject: [PATCH] Implement `Send`/`Sync` for `CopyTaggedPtr` --- .../src/tagged_ptr/copy.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs index 02dcbd389df..68d660f48b4 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs @@ -253,6 +253,26 @@ fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { } } +// Safety: +// `CopyTaggedPtr` is semantically just `{ ptr: P, tag: T }`, as such +// it's ok to implement `Sync` as long as `P: Sync, T: Sync` +unsafe impl Sync for CopyTaggedPtr +where + P: Sync + Pointer, + T: Sync + Tag, +{ +} + +// Safety: +// `CopyTaggedPtr` is semantically just `{ ptr: P, tag: T }`, as such +// it's ok to implement `Send` as long as `P: Send, T: Send` +unsafe impl Send for CopyTaggedPtr +where + P: Send + Pointer, + T: Send + Tag, +{ +} + /// Test that `new` does not compile if there is not enough alignment for the /// tag in the pointer. ///