Closed sparecycles closed 1 year ago
They just inherit the item type's sendability/syncability, not the generic parameter's. &mut T: Send
if T: Send
and &T: Send
if T: Sync
.
Thanks, I see now why Iter<Sync>
could be Send, but I'm not sure about related structs like Drain
or IntoIter
s.
It's interesting that Iter<T: Send>
is not Send, but IterMut<T: Send>
is.
I am closing this issue as it is not a bug and working as intended.
You really are seeing Sync
implying Send
on, e.g.,
https://github.com/rust-lang/rust/blob/b6852428a8ea9728369b64b9964cad8e258403d3/library/alloc/src/collections/linked_list.rs#L1990-L1991
and that's fine?
Okay, looks like this is actually intentional, but it's still a bit cryptic.
https://github.com/rust-lang/rust/pull/27615#discussion_r36677777
There are a few places where an
Iter
implementsSend
when the item/key/value traits areSync
. The other related types (IterMut
, etc...) implementSync
forSync
items andSend
forSend
items.See line 1209 in https://github.com/rust-lang/rust/blob/917945d662c42053383fe3e71cb0f313d585e459/src/liballoc/collections/linked_list.rs#L1202-L1218
and also in https://github.com/rust-lang/rust/blob/917945d662c42053383fe3e71cb0f313d585e459/src/libcore/slice/mod.rs#L2650-L2653
as well as https://github.com/rust-lang/rust/blob/917945d662c42053383fe3e71cb0f313d585e459/src/libstd/collections/hash/table.rs#L916-L917
( Noticed this pattern in https://github.com/hyperium/http/pull/239 )