Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded Send/Sync bounds on Arc, Mutex, RwLock and sync::mpsc #23176

Merged
merged 3 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<T> Deref for Arc<T> {
}
}

impl<T: Send + Sync + Clone> Arc<T> {
impl<T: Clone> Arc<T> {
/// Make a mutable reference from the given `Arc<T>`.
///
/// This is also referred to as a copy-on-write operation because the inner data is cloned if
Expand Down Expand Up @@ -300,7 +300,7 @@ impl<T: Send + Sync + Clone> Arc<T> {

#[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Sync + Send> Drop for Arc<T> {
impl<T> Drop for Arc<T> {
/// Drops the `Arc<T>`.
///
/// This will decrement the strong reference count. If the strong reference count becomes zero
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<T: Sync + Send> Drop for Arc<T> {

#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T: Sync + Send> Weak<T> {
impl<T> Weak<T> {
/// Upgrades a weak reference to a strong reference.
///
/// Upgrades the `Weak<T>` reference to an `Arc<T>`, if possible.
Expand Down Expand Up @@ -406,7 +406,7 @@ impl<T: Sync + Send> Weak<T> {

#[unstable(feature = "alloc",
reason = "Weak pointers may not belong in this module.")]
impl<T: Sync + Send> Clone for Weak<T> {
impl<T> Clone for Weak<T> {
/// Makes a clone of the `Weak<T>`.
///
/// This increases the weak reference count.
Expand All @@ -430,7 +430,7 @@ impl<T: Sync + Send> Clone for Weak<T> {

#[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Sync + Send> Drop for Weak<T> {
impl<T> Drop for Weak<T> {
/// Drops the `Weak<T>`.
///
/// This will decrement the weak reference count.
Expand Down
24 changes: 12 additions & 12 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
/// println!("{:?}", rx.recv().unwrap());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
let a = Arc::new(UnsafeCell::new(oneshot::Packet::new()));
(Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a)))
}
Expand Down Expand Up @@ -525,7 +525,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
/// assert_eq!(rx.recv().unwrap(), 2);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn sync_channel<T: Send>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound)));
(SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a)))
}
Expand All @@ -534,7 +534,7 @@ pub fn sync_channel<T: Send>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
// Sender
////////////////////////////////////////////////////////////////////////////////

impl<T: Send> Sender<T> {
impl<T> Sender<T> {
fn new(inner: Flavor<T>) -> Sender<T> {
Sender {
inner: UnsafeCell::new(inner),
Expand Down Expand Up @@ -616,7 +616,7 @@ impl<T: Send> Sender<T> {
}

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

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

impl<T: Send> SyncSender<T> {
impl<T> SyncSender<T> {
fn new(inner: Arc<UnsafeCell<sync::Packet<T>>>) -> SyncSender<T> {
SyncSender { inner: inner }
}
Expand Down Expand Up @@ -717,7 +717,7 @@ impl<T: Send> SyncSender<T> {
}

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

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

impl<T: Send> Receiver<T> {
impl<T> Receiver<T> {
fn new(inner: Flavor<T>) -> Receiver<T> {
Receiver { inner: UnsafeCell::new(inner) }
}
Expand Down Expand Up @@ -855,7 +855,7 @@ impl<T: Send> Receiver<T> {
}
}

impl<T: Send> select::Packet for Receiver<T> {
impl<T> select::Packet for Receiver<T> {
fn can_recv(&self) -> bool {
loop {
let new_port = match *unsafe { self.inner() } {
Expand Down Expand Up @@ -942,15 +942,15 @@ impl<T: Send> select::Packet for Receiver<T> {
}

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

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

#[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send> Drop for Receiver<T> {
impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
match *unsafe { self.inner_mut() } {
Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); },
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/mpsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<T> Node<T> {
}
}

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

#[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send> Drop for Queue<T> {
impl<T> Drop for Queue<T> {
fn drop(&mut self) {
unsafe {
let mut cur = *self.tail.get();
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum MyUpgrade<T> {
GoUp(Receiver<T>),
}

impl<T: Send> Packet<T> {
impl<T> Packet<T> {
pub fn new() -> Packet<T> {
Packet {
data: None,
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<T: Send> Packet<T> {
}

#[unsafe_destructor]
impl<T: Send> Drop for Packet<T> {
impl<T> Drop for Packet<T> {
fn drop(&mut self) {
assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum Failure {
Disconnected,
}

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

#[unsafe_destructor]
impl<T: Send> Drop for Packet<T> {
impl<T> Drop for Packet<T> {
fn drop(&mut self) {
// Note that this load is not only an assert for correctness about
// disconnection, but also a proper fence before the read of
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sync/mpsc/spsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ unsafe impl<T: Send> Send for Queue<T> { }

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

impl<T: Send> Node<T> {
impl<T> Node<T> {
fn new() -> *mut Node<T> {
unsafe {
boxed::into_raw(box Node {
Expand All @@ -89,7 +89,7 @@ impl<T: Send> Node<T> {
}
}

impl<T: Send> Queue<T> {
impl<T> Queue<T> {
/// Creates a new queue.
///
/// This is unsafe as the type system doesn't enforce a single
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<T: Send> Queue<T> {
}

#[unsafe_destructor]
impl<T: Send> Drop for Queue<T> {
impl<T> Drop for Queue<T> {
fn drop(&mut self) {
unsafe {
let mut cur = *self.first.get();
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ enum Message<T> {
GoUp(Receiver<T>),
}

impl<T: Send> Packet<T> {
impl<T> Packet<T> {
pub fn new() -> Packet<T> {
Packet {
queue: unsafe { spsc::Queue::new(128) },
Expand Down Expand Up @@ -472,7 +472,7 @@ impl<T: Send> Packet<T> {
}

#[unsafe_destructor]
impl<T: Send> Drop for Packet<T> {
impl<T> Drop for Packet<T> {
fn drop(&mut self) {
// Note that this load is not only an assert for correctness about
// disconnection, but also a proper fence before the read of
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/sync/mpsc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ pub enum Failure {

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

impl<T: Send> Packet<T> {
impl<T> Packet<T> {
pub fn new(cap: usize) -> Packet<T> {
Packet {
channels: AtomicUsize::new(1),
Expand Down Expand Up @@ -412,7 +412,7 @@ impl<T: Send> Packet<T> {
}

#[unsafe_destructor]
impl<T: Send> Drop for Packet<T> {
impl<T> Drop for Packet<T> {
fn drop(&mut self) {
assert_eq!(self.channels.load(Ordering::SeqCst), 0);
let mut guard = self.lock.lock().unwrap();
Expand Down
8 changes: 5 additions & 3 deletions src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub struct Mutex<T> {
data: UnsafeCell<T>,
}

// these are the only places where `T: Send` matters; all other
// functionality works fine on a single thread.
unsafe impl<T: Send> Send for Mutex<T> { }

unsafe impl<T: Send> Sync for Mutex<T> { }
Expand Down Expand Up @@ -179,7 +181,7 @@ pub const MUTEX_INIT: StaticMutex = StaticMutex {
poison: poison::FLAG_INIT,
};

impl<T: Send> Mutex<T> {
impl<T> Mutex<T> {
/// Creates a new mutex in an unlocked state ready for use.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(t: T) -> Mutex<T> {
Expand Down Expand Up @@ -242,7 +244,7 @@ impl<T: Send> Mutex<T> {

#[unsafe_destructor]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send> Drop for Mutex<T> {
impl<T> Drop for Mutex<T> {
fn drop(&mut self) {
// This is actually safe b/c we know that there is no further usage of
// this mutex (it's up to the user to arrange for a mutex to get
Expand All @@ -252,7 +254,7 @@ impl<T: Send> Drop for Mutex<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug + Send + 'static> fmt::Debug for Mutex<T> {
impl<T: fmt::Debug + 'static> fmt::Debug for Mutex<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.try_lock() {
Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", *guard),
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct RwLockWriteGuard<'a, T: 'a> {

impl<'a, T> !marker::Send for RwLockWriteGuard<'a, T> {}

impl<T: Send + Sync> RwLock<T> {
impl<T> RwLock<T> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// # Examples
Expand Down Expand Up @@ -257,7 +257,7 @@ impl<T> Drop for RwLock<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug + Send + Sync> fmt::Debug for RwLock<T> {
impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.try_read() {
Ok(guard) => write!(f, "RwLock {{ data: {:?} }}", *guard),
Expand Down