Skip to content

Commit 0f6b43a

Browse files
committed
Remove unneeded Send bounds from std::sync::mpsc.
The requirements `T: Send` only matter if the channel crosses thread boundaries i.e. the `Sender` or `Reciever` are sent across thread boundaries, and which is adequately controlled by the impls of `Send` for them. If `T` doesn't satisfy the bounds, then the types cannot cross thread boundaries and so everything is still safe (the pair of types collectively behave like a `Rc<RefCell<VecDeque>>`, or something of that nature).
1 parent 25d070f commit 0f6b43a

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

src/libstd/sync/mpsc/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
485485
/// println!("{:?}", rx.recv().unwrap());
486486
/// ```
487487
#[stable(feature = "rust1", since = "1.0.0")]
488-
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
488+
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
489489
let a = Arc::new(UnsafeCell::new(oneshot::Packet::new()));
490490
(Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a)))
491491
}
@@ -525,7 +525,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
525525
/// assert_eq!(rx.recv().unwrap(), 2);
526526
/// ```
527527
#[stable(feature = "rust1", since = "1.0.0")]
528-
pub fn sync_channel<T: Send>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
528+
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
529529
let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound)));
530530
(SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a)))
531531
}
@@ -534,7 +534,7 @@ pub fn sync_channel<T: Send>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
534534
// Sender
535535
////////////////////////////////////////////////////////////////////////////////
536536

537-
impl<T: Send> Sender<T> {
537+
impl<T> Sender<T> {
538538
fn new(inner: Flavor<T>) -> Sender<T> {
539539
Sender {
540540
inner: UnsafeCell::new(inner),
@@ -616,7 +616,7 @@ impl<T: Send> Sender<T> {
616616
}
617617

618618
#[stable(feature = "rust1", since = "1.0.0")]
619-
impl<T: Send> Clone for Sender<T> {
619+
impl<T> Clone for Sender<T> {
620620
fn clone(&self) -> Sender<T> {
621621
let (packet, sleeper, guard) = match *unsafe { self.inner() } {
622622
Flavor::Oneshot(ref p) => {
@@ -662,7 +662,7 @@ impl<T: Send> Clone for Sender<T> {
662662

663663
#[unsafe_destructor]
664664
#[stable(feature = "rust1", since = "1.0.0")]
665-
impl<T: Send> Drop for Sender<T> {
665+
impl<T> Drop for Sender<T> {
666666
fn drop(&mut self) {
667667
match *unsafe { self.inner_mut() } {
668668
Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); },
@@ -677,7 +677,7 @@ impl<T: Send> Drop for Sender<T> {
677677
// SyncSender
678678
////////////////////////////////////////////////////////////////////////////////
679679

680-
impl<T: Send> SyncSender<T> {
680+
impl<T> SyncSender<T> {
681681
fn new(inner: Arc<UnsafeCell<sync::Packet<T>>>) -> SyncSender<T> {
682682
SyncSender { inner: inner }
683683
}
@@ -717,7 +717,7 @@ impl<T: Send> SyncSender<T> {
717717
}
718718

719719
#[stable(feature = "rust1", since = "1.0.0")]
720-
impl<T: Send> Clone for SyncSender<T> {
720+
impl<T> Clone for SyncSender<T> {
721721
fn clone(&self) -> SyncSender<T> {
722722
unsafe { (*self.inner.get()).clone_chan(); }
723723
return SyncSender::new(self.inner.clone());
@@ -726,7 +726,7 @@ impl<T: Send> Clone for SyncSender<T> {
726726

727727
#[unsafe_destructor]
728728
#[stable(feature = "rust1", since = "1.0.0")]
729-
impl<T: Send> Drop for SyncSender<T> {
729+
impl<T> Drop for SyncSender<T> {
730730
fn drop(&mut self) {
731731
unsafe { (*self.inner.get()).drop_chan(); }
732732
}
@@ -736,7 +736,7 @@ impl<T: Send> Drop for SyncSender<T> {
736736
// Receiver
737737
////////////////////////////////////////////////////////////////////////////////
738738

739-
impl<T: Send> Receiver<T> {
739+
impl<T> Receiver<T> {
740740
fn new(inner: Flavor<T>) -> Receiver<T> {
741741
Receiver { inner: UnsafeCell::new(inner) }
742742
}
@@ -855,7 +855,7 @@ impl<T: Send> Receiver<T> {
855855
}
856856
}
857857

858-
impl<T: Send> select::Packet for Receiver<T> {
858+
impl<T> select::Packet for Receiver<T> {
859859
fn can_recv(&self) -> bool {
860860
loop {
861861
let new_port = match *unsafe { self.inner() } {
@@ -942,15 +942,15 @@ impl<T: Send> select::Packet for Receiver<T> {
942942
}
943943

944944
#[stable(feature = "rust1", since = "1.0.0")]
945-
impl<'a, T: Send> Iterator for Iter<'a, T> {
945+
impl<'a, T> Iterator for Iter<'a, T> {
946946
type Item = T;
947947

948948
fn next(&mut self) -> Option<T> { self.rx.recv().ok() }
949949
}
950950

951951
#[unsafe_destructor]
952952
#[stable(feature = "rust1", since = "1.0.0")]
953-
impl<T: Send> Drop for Receiver<T> {
953+
impl<T> Drop for Receiver<T> {
954954
fn drop(&mut self) {
955955
match *unsafe { self.inner_mut() } {
956956
Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); },

src/libstd/sync/mpsc/mpsc_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<T> Node<T> {
8989
}
9090
}
9191

92-
impl<T: Send> Queue<T> {
92+
impl<T> Queue<T> {
9393
/// Creates a new queue that is safe to share among multiple producers and
9494
/// one consumer.
9595
pub fn new() -> Queue<T> {
@@ -140,7 +140,7 @@ impl<T: Send> Queue<T> {
140140

141141
#[unsafe_destructor]
142142
#[stable(feature = "rust1", since = "1.0.0")]
143-
impl<T: Send> Drop for Queue<T> {
143+
impl<T> Drop for Queue<T> {
144144
fn drop(&mut self) {
145145
unsafe {
146146
let mut cur = *self.tail.get();

src/libstd/sync/mpsc/oneshot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ enum MyUpgrade<T> {
8888
GoUp(Receiver<T>),
8989
}
9090

91-
impl<T: Send> Packet<T> {
91+
impl<T> Packet<T> {
9292
pub fn new() -> Packet<T> {
9393
Packet {
9494
data: None,
@@ -368,7 +368,7 @@ impl<T: Send> Packet<T> {
368368
}
369369

370370
#[unsafe_destructor]
371-
impl<T: Send> Drop for Packet<T> {
371+
impl<T> Drop for Packet<T> {
372372
fn drop(&mut self) {
373373
assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED);
374374
}

src/libstd/sync/mpsc/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub enum Failure {
6464
Disconnected,
6565
}
6666

67-
impl<T: Send> Packet<T> {
67+
impl<T> Packet<T> {
6868
// Creation of a packet *must* be followed by a call to postinit_lock
6969
// and later by inherit_blocker
7070
pub fn new() -> Packet<T> {
@@ -474,7 +474,7 @@ impl<T: Send> Packet<T> {
474474
}
475475

476476
#[unsafe_destructor]
477-
impl<T: Send> Drop for Packet<T> {
477+
impl<T> Drop for Packet<T> {
478478
fn drop(&mut self) {
479479
// Note that this load is not only an assert for correctness about
480480
// disconnection, but also a proper fence before the read of

src/libstd/sync/mpsc/spsc_queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ unsafe impl<T: Send> Send for Queue<T> { }
7878

7979
unsafe impl<T: Send> Sync for Queue<T> { }
8080

81-
impl<T: Send> Node<T> {
81+
impl<T> Node<T> {
8282
fn new() -> *mut Node<T> {
8383
unsafe {
8484
boxed::into_raw(box Node {
@@ -89,7 +89,7 @@ impl<T: Send> Node<T> {
8989
}
9090
}
9191

92-
impl<T: Send> Queue<T> {
92+
impl<T> Queue<T> {
9393
/// Creates a new queue.
9494
///
9595
/// This is unsafe as the type system doesn't enforce a single
@@ -227,7 +227,7 @@ impl<T: Send> Queue<T> {
227227
}
228228

229229
#[unsafe_destructor]
230-
impl<T: Send> Drop for Queue<T> {
230+
impl<T> Drop for Queue<T> {
231231
fn drop(&mut self) {
232232
unsafe {
233233
let mut cur = *self.first.get();

src/libstd/sync/mpsc/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum Message<T> {
7474
GoUp(Receiver<T>),
7575
}
7676

77-
impl<T: Send> Packet<T> {
77+
impl<T> Packet<T> {
7878
pub fn new() -> Packet<T> {
7979
Packet {
8080
queue: unsafe { spsc::Queue::new(128) },
@@ -472,7 +472,7 @@ impl<T: Send> Packet<T> {
472472
}
473473

474474
#[unsafe_destructor]
475-
impl<T: Send> Drop for Packet<T> {
475+
impl<T> Drop for Packet<T> {
476476
fn drop(&mut self) {
477477
// Note that this load is not only an assert for correctness about
478478
// disconnection, but also a proper fence before the read of

src/libstd/sync/mpsc/sync.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ pub enum Failure {
113113

114114
/// Atomically blocks the current thread, placing it into `slot`, unlocking `lock`
115115
/// in the meantime. This re-locks the mutex upon returning.
116-
fn wait<'a, 'b, T: Send>(lock: &'a Mutex<State<T>>,
117-
mut guard: MutexGuard<'b, State<T>>,
118-
f: fn(SignalToken) -> Blocker)
119-
-> MutexGuard<'a, State<T>>
116+
fn wait<'a, 'b, T>(lock: &'a Mutex<State<T>>,
117+
mut guard: MutexGuard<'b, State<T>>,
118+
f: fn(SignalToken) -> Blocker)
119+
-> MutexGuard<'a, State<T>>
120120
{
121121
let (wait_token, signal_token) = blocking::tokens();
122122
match mem::replace(&mut guard.blocker, f(signal_token)) {
@@ -136,7 +136,7 @@ fn wakeup<T>(token: SignalToken, guard: MutexGuard<State<T>>) {
136136
token.signal();
137137
}
138138

139-
impl<T: Send> Packet<T> {
139+
impl<T> Packet<T> {
140140
pub fn new(cap: usize) -> Packet<T> {
141141
Packet {
142142
channels: AtomicUsize::new(1),
@@ -412,7 +412,7 @@ impl<T: Send> Packet<T> {
412412
}
413413

414414
#[unsafe_destructor]
415-
impl<T: Send> Drop for Packet<T> {
415+
impl<T> Drop for Packet<T> {
416416
fn drop(&mut self) {
417417
assert_eq!(self.channels.load(Ordering::SeqCst), 0);
418418
let mut guard = self.lock.lock().unwrap();

0 commit comments

Comments
 (0)