From a1850f83c458fb8966cf44f5d96ed8f0f9328643 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Wed, 12 May 2021 09:58:21 +0200 Subject: [PATCH] feat(metadata): remove manual `Send + Sync` impls for metadata types Removes manual `Send` and `Sync` impls for these types as they weren't necessary: - `metadata::Iter` - `metadata::IterMut` - `metadata::ValueDrain` - `metadata::ValueIterMut` Since all the types they contained were `Send + Sync` we can rely on the compiler automatically adding the impls. Also added some tests to ensure we don't accidentally make them `!Send` or `!Sync` in the future. Fixes https://github.com/hyperium/tonic/issues/636 --- tonic/src/metadata/map.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tonic/src/metadata/map.rs b/tonic/src/metadata/map.rs index cbef3e101..461a9fb54 100644 --- a/tonic/src/metadata/map.rs +++ b/tonic/src/metadata/map.rs @@ -1244,9 +1244,6 @@ impl<'a> Iterator for Iter<'a> { } } -unsafe impl<'a> Sync for Iter<'a> {} -unsafe impl<'a> Send for Iter<'a> {} - // ===== impl IterMut ===== impl<'a> Iterator for IterMut<'a> { @@ -1274,9 +1271,6 @@ impl<'a> Iterator for IterMut<'a> { } } -unsafe impl<'a> Sync for IterMut<'a> {} -unsafe impl<'a> Send for IterMut<'a> {} - // ===== impl ValueDrain ===== impl<'a, VE: ValueEncoding> Iterator for ValueDrain<'a, VE> { @@ -1293,9 +1287,6 @@ impl<'a, VE: ValueEncoding> Iterator for ValueDrain<'a, VE> { } } -unsafe impl<'a, VE: ValueEncoding> Sync for ValueDrain<'a, VE> {} -unsafe impl<'a, VE: ValueEncoding> Send for ValueDrain<'a, VE> {} - // ===== impl Keys ===== impl<'a> Iterator for Keys<'a> { @@ -1425,9 +1416,6 @@ where } } -unsafe impl<'a, VE: ValueEncoding> Sync for ValueIterMut<'a, VE> {} -unsafe impl<'a, VE: ValueEncoding> Send for ValueIterMut<'a, VE> {} - // ===== impl Entry ===== impl<'a, VE: ValueEncoding> Entry<'a, VE> { @@ -2725,4 +2713,18 @@ mod tests { } assert!(found_x_word_bin); } + + #[allow(dead_code)] + fn value_drain_is_send_sync() { + fn is_send_sync() {} + + is_send_sync::>(); + is_send_sync::>(); + + is_send_sync::>(); + is_send_sync::>(); + + is_send_sync::>(); + is_send_sync::>(); + } }