From 9cca96545faf2cfc972cc67b83deae2a78935c43 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Tue, 8 Sep 2015 00:36:29 +0200 Subject: some more clippy-based improvements --- src/libstd/sync/mpsc/mod.rs | 8 ++++---- src/libstd/sync/mpsc/spsc_queue.rs | 7 +++---- src/libstd/sync/mpsc/stream.rs | 9 ++------- src/libstd/sync/mpsc/sync.rs | 12 +++--------- src/libstd/sync/mutex.rs | 5 +++-- 5 files changed, 15 insertions(+), 26 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index c37c0405bbb..8c5cec969a6 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -397,7 +397,7 @@ enum Flavor { #[doc(hidden)] trait UnsafeFlavor { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell>; + fn inner_unsafe(&self) -> &UnsafeCell>; unsafe fn inner_mut<'a>(&'a self) -> &'a mut Flavor { &mut *self.inner_unsafe().get() } @@ -406,12 +406,12 @@ trait UnsafeFlavor { } } impl UnsafeFlavor for Sender { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell> { + fn inner_unsafe(&self) -> &UnsafeCell> { &self.inner } } impl UnsafeFlavor for Receiver { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell> { + fn inner_unsafe(&self) -> &UnsafeCell> { &self.inner } } @@ -677,7 +677,7 @@ impl SyncSender { impl Clone for SyncSender { fn clone(&self) -> SyncSender { unsafe { (*self.inner.get()).clone_chan(); } - return SyncSender::new(self.inner.clone()); + SyncSender::new(self.inner.clone()) } } diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 819f75c006b..ffd33f8518f 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -196,7 +196,7 @@ impl Queue { let _: Box> = Box::from_raw(tail); } } - return ret; + ret } } @@ -207,14 +207,13 @@ impl Queue { /// The reference returned is invalid if it is not used before the consumer /// pops the value off the queue. If the producer then pushes another value /// onto the queue, it will overwrite the value pointed to by the reference. - pub fn peek<'a>(&'a self) -> Option<&'a mut T> { + pub fn peek(&self) -> Option<&mut T> { // This is essentially the same as above with all the popping bits // stripped out. unsafe { let tail = *self.tail.get(); let next = (*tail).next.load(Ordering::Acquire); - if next.is_null() { return None } - return (*next).value.as_mut(); + if next.is_null() { None } else { (*next).value.as_mut() } } } } diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index a9da1b12f7d..e8012ca470b 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -307,12 +307,7 @@ impl Packet { steals, DISCONNECTED, Ordering::SeqCst); cnt != DISCONNECTED && cnt != steals } { - loop { - match self.queue.pop() { - Some(..) => { steals += 1; } - None => break - } - } + while let Some(_) = self.queue.pop() { steals += 1; } } // At this point in time, we have gated all future senders from sending, @@ -378,7 +373,7 @@ impl Packet { // previous value is positive because we're not going to sleep let prev = self.bump(1); assert!(prev == DISCONNECTED || prev >= 0); - return ret; + ret } } } diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 84d758cf9b3..b98fc2859af 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -254,7 +254,7 @@ impl Packet { assert!(guard.buf.size() > 0); let ret = guard.buf.dequeue(); self.wakeup_senders(waited, guard); - return Ok(ret); + Ok(ret) } pub fn try_recv(&self) -> Result { @@ -267,8 +267,7 @@ impl Packet { // Be sure to wake up neighbors let ret = Ok(guard.buf.dequeue()); self.wakeup_senders(false, guard); - - return ret; + ret } // Wake up pending senders after some data has been received @@ -356,12 +355,7 @@ impl Packet { }; mem::drop(guard); - loop { - match queue.dequeue() { - Some(token) => { token.signal(); } - None => break, - } - } + while let Some(token) = queue.dequeue() { token.signal(); } waiter.map(|t| t.signal()); } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index e56e5a72c13..846a97b547d 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -334,13 +334,14 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> { impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { type Target = T; - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } + #[stable(feature = "rust1", since = "1.0.0")] impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> { - fn deref_mut<'a>(&'a mut self) -> &'a mut T { + fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__data.get() } } } -- cgit 1.4.1-3-g733a5