From 8505082f168eb44407352dd14d591918af86d3a2 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 14 Dec 2023 14:09:17 -0800 Subject: [PATCH] Improve thread safety docs/bounds for PrimitiveMut PiperOrigin-RevId: 591047379 --- rust/primitive.rs | 2 ++ rust/vtable.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rust/primitive.rs b/rust/primitive.rs index ea742181bf9f6..193901bb4b443 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -37,6 +37,8 @@ impl<'msg, T> PrimitiveMut<'msg, T> { } } +// SAFETY: all `T` that can perform mutations don't mutate through a shared +// reference. unsafe impl<'msg, T> Sync for PrimitiveMut<'msg, T> {} impl<'msg, T> PrimitiveMut<'msg, T> diff --git a/rust/vtable.rs b/rust/vtable.rs index 2691125b46cd2..311809608369b 100644 --- a/rust/vtable.rs +++ b/rust/vtable.rs @@ -432,6 +432,8 @@ pub trait PrimitiveWithRawVTable: + Debug + 'static + ProxiedWithPresence + + Sync + + Send + for<'msg> Proxied = Self, Mut<'msg> = PrimitiveMut<'msg, Self>> { }