Mark owned Repeated & Map types as Send & Sync.

PiperOrigin-RevId: 640063798
pull/17005/head
Jakob Buchgraber 9 months ago committed by Copybara-Service
parent 986ef8d80b
commit 3c9978d4bd
  1. 7
      rust/map.rs
  2. 10
      rust/repeated.rs

@ -64,6 +64,13 @@ pub struct Map<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> {
_phantom: PhantomData<(PhantomData<K>, PhantomData<V>)>,
}
// SAFETY: `Map` is Sync because it does not implement interior mutability.
unsafe impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Sync for Map<K, V> {}
// SAFETY: `Map` is Send because it's not bound to a specific thread e.g.
// it does not use thread-local data or similar.
unsafe impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Send for Map<K, V> {}
impl<K: ?Sized + Proxied, V: ?Sized + ProxiedInMapValue<K>> Drop for Map<K, V> {
fn drop(&mut self) {
// SAFETY:

@ -341,6 +341,13 @@ pub struct Repeated<T: ?Sized + ProxiedInRepeated> {
_phantom: PhantomData<T>,
}
// SAFETY: `Repeated` is Sync because it does not implement interior mutability.
unsafe impl<T: ?Sized + ProxiedInRepeated> Sync for Repeated<T> {}
// SAFETY: `Repeated` is Send because it's not bound to a specific thread e.g.
// it does not use thread-local data or similar.
unsafe impl<T: ?Sized + ProxiedInRepeated> Send for Repeated<T> {}
impl<T: ?Sized + ProxiedInRepeated> Repeated<T> {
pub fn new() -> Self {
T::repeated_new(Private)
@ -368,9 +375,6 @@ impl<T: ?Sized + ProxiedInRepeated> Drop for Repeated<T> {
}
}
// SAFETY: `Repeated` does not allow for shared mutability.
unsafe impl<T: ProxiedInRepeated> Sync for Repeated<T> {}
impl<T> Proxied for Repeated<T>
where
T: ProxiedInRepeated + ?Sized,

Loading…
Cancel
Save