From 9c8666a5c962bb009e6c5baf183d303f85efb642 Mon Sep 17 00:00:00 2001 From: kyren Date: Wed, 24 May 2023 09:10:59 -0400 Subject: [PATCH] Implement Send and Sync unconditionally for exposed Id type. (#3801) --- wgpu/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 1ba1315072..ca0c6ac50d 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -4263,6 +4263,15 @@ impl Surface { #[repr(transparent)] pub struct Id(core::num::NonZeroU64, std::marker::PhantomData<*mut T>); +// SAFETY: `Id` is a bare `NonZeroU64`, the type parameter is a marker purely to avoid confusing Ids +// returned for different types , so `Id` can safely implement Send and Sync. +#[cfg(feature = "expose-ids")] +unsafe impl Send for Id {} + +// SAFETY: See the implementation for `Send`. +#[cfg(feature = "expose-ids")] +unsafe impl Sync for Id {} + #[cfg(feature = "expose-ids")] impl Clone for Id { fn clone(&self) -> Self {