Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 91df320

Browse files
impl Send and Sync cleanup
This commit removes the unnecessary `unsafe impl Send` for `Sender` and `Receiver` as they both `Send` that from the inner `mpmc`. Additionally, this adds an unconditional `impl Sync` for `Sender` and `Receiver`.
1 parent 90740d3 commit 91df320

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

‎library/std/src/sync/oneshot.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ pub struct Sender<T> {
2424
inner: mpmc::Sender<T>,
2525
}
2626

27-
/// The sending end of the channel can be sent between threads, as long as it is not used to
28-
/// receive non-sendable things.
27+
/// SAFETY: Since the only methods in which synchronization must occur take full ownership of the
28+
/// [`Sender`], it is perfectly safe to share a &[`Sender`] between threads (as it is effectively
29+
/// useless without full ownership).
2930
#[unstable(feature = "oneshot_channel", issue = "143674")]
30-
unsafe impl<T: Send> Send for Sender<T> {}
31-
32-
/// FIXME: Try to boil down <https://github.com/rust-lang/rust/pull/111087> into a doc comment.
33-
#[unstable(feature = "oneshot_channel", issue = "143674")]
34-
unsafe impl<T: Send> Sync for Sender<T> {}
31+
unsafe impl<T> Sync for Sender<T> {}
3532

3633
impl<T> Sender<T> {
3734
/// Attempts to send a value through this channel. This can only fail if the corresponding
@@ -62,14 +59,11 @@ pub struct Receiver<T> {
6259
inner: mpmc::Receiver<T>,
6360
}
6461

65-
/// The receiving end of the channel can be sent between threads, as long as it is not used to
66-
/// receive non-sendable things.
67-
#[unstable(feature = "oneshot_channel", issue = "143674")]
68-
unsafe impl<T: Send> Send for Receiver<T> {}
69-
70-
/// FIXME: Why is `mpsc::Receiver` !Sync but `mpmc::Receiver` is? Write this in a doc comment.
62+
/// SAFETY: Since the only methods in which synchronization must occur take full ownership of the
63+
/// [`Receiver`], it is perfectly safe to share a &[`Receiver`] between threads (as it is unable to
64+
/// receive any values without full ownership).
7165
#[unstable(feature = "oneshot_channel", issue = "143674")]
72-
impl<T> !Sync for Receiver<T> {}
66+
unsafeimpl<T> Sync for Receiver<T> {}
7367

7468
impl<T> Receiver<T> {
7569
/// Receives the value from the sending end, blocking the calling thread until it gets it.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /