From 4acfd0b7799a1a71821019235d23881ee2ad9670 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 23 May 2020 03:11:57 +0900 Subject: [PATCH] Apply rust 2018 idioms --- README.md | 6 - crossbeam-channel/README.md | 7 - .../benchmarks/crossbeam-channel.rs | 3 - .../benchmarks/crossbeam-deque.rs | 5 +- crossbeam-channel/benchmarks/flume.rs | 2 - .../benchmarks/futures-channel.rs | 3 - crossbeam-channel/benchmarks/lockfree.rs | 3 - crossbeam-channel/benchmarks/message.rs | 2 +- crossbeam-channel/benchmarks/mpmc.rs | 3 - crossbeam-channel/benchmarks/mpsc.rs | 2 - crossbeam-channel/benchmarks/segqueue.rs | 2 - crossbeam-channel/examples/fibonacci.rs | 2 - crossbeam-channel/examples/matching.rs | 6 +- crossbeam-channel/examples/stopwatch.rs | 6 +- crossbeam-channel/src/channel.rs | 40 ++- crossbeam-channel/src/err.rs | 22 +- crossbeam-channel/src/flavors/array.rs | 12 +- crossbeam-channel/src/flavors/list.rs | 12 +- crossbeam-channel/src/flavors/zero.rs | 12 +- crossbeam-channel/src/lib.rs | 18 +- crossbeam-channel/src/select.rs | 18 +- crossbeam-channel/src/select_macro.rs | 279 +++++++++--------- crossbeam-channel/src/utils.rs | 8 +- crossbeam-channel/tests/after.rs | 7 +- crossbeam-channel/tests/array.rs | 7 +- crossbeam-channel/tests/golang.rs | 5 +- crossbeam-channel/tests/iter.rs | 3 - crossbeam-channel/tests/list.rs | 7 +- crossbeam-channel/tests/mpsc.rs | 7 +- crossbeam-channel/tests/never.rs | 6 +- crossbeam-channel/tests/ready.rs | 3 - crossbeam-channel/tests/same_channel.rs | 2 - crossbeam-channel/tests/select.rs | 3 - crossbeam-channel/tests/select_macro.rs | 6 +- crossbeam-channel/tests/thread_locals.rs | 6 +- crossbeam-channel/tests/tick.rs | 7 +- crossbeam-channel/tests/zero.rs | 7 +- crossbeam-deque/README.md | 6 - crossbeam-deque/src/deque.rs | 10 +- crossbeam-deque/src/lib.rs | 10 +- crossbeam-deque/tests/fifo.rs | 10 +- crossbeam-deque/tests/injector.rs | 10 +- crossbeam-deque/tests/lifo.rs | 10 +- crossbeam-deque/tests/steal.rs | 6 +- crossbeam-epoch/README.md | 6 - crossbeam-epoch/benches/defer.rs | 6 +- crossbeam-epoch/benches/flush.rs | 5 +- crossbeam-epoch/benches/pin.rs | 5 +- crossbeam-epoch/examples/sanitize.rs | 5 +- crossbeam-epoch/examples/treiber_stack.rs | 7 +- crossbeam-epoch/src/atomic.rs | 38 +-- crossbeam-epoch/src/collector.rs | 4 +- crossbeam-epoch/src/default.rs | 1 + crossbeam-epoch/src/deferred.rs | 2 +- crossbeam-epoch/src/guard.rs | 6 +- crossbeam-epoch/src/internal.rs | 3 +- crossbeam-epoch/src/lib.rs | 19 +- crossbeam-epoch/src/sync/list.rs | 4 +- crossbeam-epoch/src/sync/queue.rs | 2 +- crossbeam-queue/README.md | 6 - crossbeam-queue/src/array_queue.rs | 2 +- crossbeam-queue/src/err.rs | 8 +- crossbeam-queue/src/lib.rs | 17 +- crossbeam-queue/src/seg_queue.rs | 2 +- crossbeam-queue/tests/array_queue.rs | 4 - crossbeam-queue/tests/seg_queue.rs | 4 - crossbeam-skiplist/README.md | 6 - crossbeam-skiplist/benches/btree.rs | 1 - crossbeam-skiplist/benches/hash.rs | 1 - crossbeam-skiplist/benches/skiplist.rs | 3 +- crossbeam-skiplist/benches/skipmap.rs | 1 - crossbeam-skiplist/examples/simple.rs | 2 - crossbeam-skiplist/src/base.rs | 70 +++-- crossbeam-skiplist/src/lib.rs | 17 +- crossbeam-skiplist/src/map.rs | 44 +-- crossbeam-skiplist/src/set.rs | 42 +-- crossbeam-skiplist/tests/base.rs | 6 +- crossbeam-skiplist/tests/map.rs | 4 +- crossbeam-skiplist/tests/set.rs | 4 +- crossbeam-utils/README.md | 6 - crossbeam-utils/benches/atomic_cell.rs | 1 - crossbeam-utils/build.rs | 2 - crossbeam-utils/src/atomic/atomic_cell.rs | 2 +- crossbeam-utils/src/atomic/mod.rs | 2 + crossbeam-utils/src/backoff.rs | 2 +- crossbeam-utils/src/cache_padded.rs | 2 +- crossbeam-utils/src/lib.rs | 13 +- crossbeam-utils/src/sync/parker.rs | 4 +- crossbeam-utils/src/sync/sharded_lock.rs | 45 +-- crossbeam-utils/src/sync/wait_group.rs | 2 +- crossbeam-utils/src/thread.rs | 25 +- crossbeam-utils/tests/atomic_cell.rs | 2 - crossbeam-utils/tests/cache_padded.rs | 2 - crossbeam-utils/tests/parker.rs | 2 - crossbeam-utils/tests/sharded_lock.rs | 3 - crossbeam-utils/tests/thread.rs | 2 - crossbeam-utils/tests/wait_group.rs | 2 - src/lib.rs | 29 +- tests/subcrates.rs | 3 +- 99 files changed, 438 insertions(+), 681 deletions(-) diff --git a/README.md b/README.md index 528afb4fa..cfff710f6 100644 --- a/README.md +++ b/README.md @@ -90,12 +90,6 @@ Add this to your `Cargo.toml`: crossbeam = "0.7" ``` -Next, add this to your crate: - -```rust -extern crate crossbeam; -``` - ## Compatibility Crossbeam supports stable Rust releases going back at least six months, diff --git a/crossbeam-channel/README.md b/crossbeam-channel/README.md index 914965135..7f5e8f714 100644 --- a/crossbeam-channel/README.md +++ b/crossbeam-channel/README.md @@ -44,13 +44,6 @@ Add this to your `Cargo.toml`: crossbeam-channel = "0.4" ``` -Next, add this to your crate: - -```rust -#[macro_use] -extern crate crossbeam_channel; -``` - ## Compatibility Crossbeam Channel supports stable Rust releases going back at least six months, diff --git a/crossbeam-channel/benchmarks/crossbeam-channel.rs b/crossbeam-channel/benchmarks/crossbeam-channel.rs index febc0d28b..506e1b230 100644 --- a/crossbeam-channel/benchmarks/crossbeam-channel.rs +++ b/crossbeam-channel/benchmarks/crossbeam-channel.rs @@ -1,6 +1,3 @@ -extern crate crossbeam; -extern crate crossbeam_channel; - use crossbeam_channel::{bounded, unbounded, Receiver, Select, Sender}; mod message; diff --git a/crossbeam-channel/benchmarks/crossbeam-deque.rs b/crossbeam-channel/benchmarks/crossbeam-deque.rs index 9e7034c54..935c1fb77 100644 --- a/crossbeam-channel/benchmarks/crossbeam-deque.rs +++ b/crossbeam-channel/benchmarks/crossbeam-deque.rs @@ -1,7 +1,4 @@ -extern crate crossbeam; -extern crate crossbeam_deque as deque; - -use crate::deque::{Steal, Worker}; +use crossbeam_deque::{Steal, Worker}; use std::thread; mod message; diff --git a/crossbeam-channel/benchmarks/flume.rs b/crossbeam-channel/benchmarks/flume.rs index ce062c30d..06b942105 100644 --- a/crossbeam-channel/benchmarks/flume.rs +++ b/crossbeam-channel/benchmarks/flume.rs @@ -1,5 +1,3 @@ -extern crate crossbeam; - mod message; const MESSAGES: usize = 5_000_000; diff --git a/crossbeam-channel/benchmarks/futures-channel.rs b/crossbeam-channel/benchmarks/futures-channel.rs index c26778bc1..82570d4f2 100644 --- a/crossbeam-channel/benchmarks/futures-channel.rs +++ b/crossbeam-channel/benchmarks/futures-channel.rs @@ -1,6 +1,3 @@ -extern crate crossbeam; -extern crate futures; - use futures::channel::mpsc; use futures::executor::ThreadPool; use futures::prelude::*; diff --git a/crossbeam-channel/benchmarks/lockfree.rs b/crossbeam-channel/benchmarks/lockfree.rs index b4c5a59ba..3ae0a0e03 100644 --- a/crossbeam-channel/benchmarks/lockfree.rs +++ b/crossbeam-channel/benchmarks/lockfree.rs @@ -1,6 +1,3 @@ -extern crate crossbeam; -extern crate lockfree; - use lockfree::channel; mod message; diff --git a/crossbeam-channel/benchmarks/message.rs b/crossbeam-channel/benchmarks/message.rs index 3bbbccd8a..f8a921ec7 100644 --- a/crossbeam-channel/benchmarks/message.rs +++ b/crossbeam-channel/benchmarks/message.rs @@ -6,7 +6,7 @@ const LEN: usize = 1; pub struct Message(pub [usize; LEN]); impl fmt::Debug for Message { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Message") } } diff --git a/crossbeam-channel/benchmarks/mpmc.rs b/crossbeam-channel/benchmarks/mpmc.rs index fe2473ba4..30a41dc98 100644 --- a/crossbeam-channel/benchmarks/mpmc.rs +++ b/crossbeam-channel/benchmarks/mpmc.rs @@ -1,6 +1,3 @@ -extern crate crossbeam; -extern crate mpmc; - use std::thread; mod message; diff --git a/crossbeam-channel/benchmarks/mpsc.rs b/crossbeam-channel/benchmarks/mpsc.rs index 46d295dd2..728fdd39a 100644 --- a/crossbeam-channel/benchmarks/mpsc.rs +++ b/crossbeam-channel/benchmarks/mpsc.rs @@ -1,5 +1,3 @@ -extern crate crossbeam; - use std::sync::mpsc; mod message; diff --git a/crossbeam-channel/benchmarks/segqueue.rs b/crossbeam-channel/benchmarks/segqueue.rs index eedb299be..1d12e093b 100644 --- a/crossbeam-channel/benchmarks/segqueue.rs +++ b/crossbeam-channel/benchmarks/segqueue.rs @@ -1,5 +1,3 @@ -extern crate crossbeam; - use crossbeam::queue::SegQueue; use std::thread; diff --git a/crossbeam-channel/examples/fibonacci.rs b/crossbeam-channel/examples/fibonacci.rs index 499887a05..cf22b7a57 100644 --- a/crossbeam-channel/examples/fibonacci.rs +++ b/crossbeam-channel/examples/fibonacci.rs @@ -1,7 +1,5 @@ //! An asynchronous fibonacci sequence generator. -extern crate crossbeam_channel; - use std::thread; use crossbeam_channel::{bounded, Sender}; diff --git a/crossbeam-channel/examples/matching.rs b/crossbeam-channel/examples/matching.rs index 4b157ff56..5421169b9 100644 --- a/crossbeam-channel/examples/matching.rs +++ b/crossbeam-channel/examples/matching.rs @@ -42,11 +42,7 @@ //! } //! ``` -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; - -use crossbeam_channel::bounded; +use crossbeam_channel::{bounded, select}; use crossbeam_utils::thread; fn main() { diff --git a/crossbeam-channel/examples/stopwatch.rs b/crossbeam-channel/examples/stopwatch.rs index 137ea210e..79957c4fe 100644 --- a/crossbeam-channel/examples/stopwatch.rs +++ b/crossbeam-channel/examples/stopwatch.rs @@ -1,14 +1,10 @@ //! Prints the elapsed time every 1 second and quits on Ctrl+C. -#[macro_use] -extern crate crossbeam_channel; -extern crate signal_hook; - use std::io; use std::thread; use std::time::{Duration, Instant}; -use crossbeam_channel::{bounded, tick, Receiver}; +use crossbeam_channel::{bounded, select, tick, Receiver}; use signal_hook::iterator::Signals; use signal_hook::SIGINT; diff --git a/crossbeam-channel/src/channel.rs b/crossbeam-channel/src/channel.rs index fa595052b..030643279 100644 --- a/crossbeam-channel/src/channel.rs +++ b/crossbeam-channel/src/channel.rs @@ -9,7 +9,9 @@ use std::time::{Duration, Instant}; use crate::context::Context; use crate::counter; -use crate::err::{RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError}; +use crate::err::{ + RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError, +}; use crate::flavors; use crate::select::{Operation, SelectHandle, Token}; @@ -134,11 +136,9 @@ pub fn bounded(cap: usize) -> (Sender, Receiver) { /// Using an `after` channel for timeouts: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::time::Duration; -/// use crossbeam_channel::{after, unbounded}; +/// use crossbeam_channel::{after, select, unbounded}; /// /// let (s, r) = unbounded::(); /// let timeout = Duration::from_millis(100); @@ -187,12 +187,10 @@ pub fn after(duration: Duration) -> Receiver { /// Using a `never` channel to optionally add a timeout to [`select!`]: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::thread; /// use std::time::{Duration, Instant}; -/// use crossbeam_channel::{after, never, unbounded}; +/// use crossbeam_channel::{after, select, never, unbounded}; /// /// let (s, r) = unbounded(); /// @@ -582,7 +580,7 @@ impl Clone for Sender { } impl fmt::Debug for Sender { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Sender { .. }") } } @@ -941,7 +939,7 @@ impl Receiver { /// /// assert_eq!(v, [1, 2, 3]); /// ``` - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, T> { Iter { receiver: self } } @@ -977,7 +975,7 @@ impl Receiver { /// /// assert_eq!(v, [1, 2]); /// ``` - pub fn try_iter(&self) -> TryIter { + pub fn try_iter(&self) -> TryIter<'_, T> { TryIter { receiver: self } } @@ -1040,7 +1038,7 @@ impl Clone for Receiver { } impl fmt::Debug for Receiver { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Receiver { .. }") } } @@ -1092,13 +1090,13 @@ impl IntoIterator for Receiver { /// /// assert_eq!(v, [1, 2, 3]); /// ``` -pub struct Iter<'a, T: 'a> { +pub struct Iter<'a, T> { receiver: &'a Receiver, } -impl<'a, T> FusedIterator for Iter<'a, T> {} +impl FusedIterator for Iter<'_, T> {} -impl<'a, T> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -1106,8 +1104,8 @@ impl<'a, T> Iterator for Iter<'a, T> { } } -impl<'a, T> fmt::Debug for Iter<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Iter<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Iter { .. }") } } @@ -1144,11 +1142,11 @@ impl<'a, T> fmt::Debug for Iter<'a, T> { /// /// assert_eq!(v, [1, 2]); /// ``` -pub struct TryIter<'a, T: 'a> { +pub struct TryIter<'a, T> { receiver: &'a Receiver, } -impl<'a, T> Iterator for TryIter<'a, T> { +impl Iterator for TryIter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -1156,8 +1154,8 @@ impl<'a, T> Iterator for TryIter<'a, T> { } } -impl<'a, T> fmt::Debug for TryIter<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for TryIter<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("TryIter { .. }") } } @@ -1206,7 +1204,7 @@ impl Iterator for IntoIter { } impl fmt::Debug for IntoIter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("IntoIter { .. }") } } diff --git a/crossbeam-channel/src/err.rs b/crossbeam-channel/src/err.rs index 4bf71440d..154413f9d 100644 --- a/crossbeam-channel/src/err.rs +++ b/crossbeam-channel/src/err.rs @@ -116,13 +116,13 @@ pub struct TryReadyError; pub struct ReadyTimeoutError; impl fmt::Debug for SendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "SendError(..)".fmt(f) } } impl fmt::Display for SendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "sending on a disconnected channel".fmt(f) } } @@ -150,7 +150,7 @@ impl SendError { } impl fmt::Debug for TrySendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { TrySendError::Full(..) => "Full(..)".fmt(f), TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f), @@ -159,7 +159,7 @@ impl fmt::Debug for TrySendError { } impl fmt::Display for TrySendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { TrySendError::Full(..) => "sending on a full channel".fmt(f), TrySendError::Disconnected(..) => "sending on a disconnected channel".fmt(f), @@ -216,13 +216,13 @@ impl TrySendError { } impl fmt::Debug for SendTimeoutError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "SendTimeoutError(..)".fmt(f) } } impl fmt::Display for SendTimeoutError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { SendTimeoutError::Timeout(..) => "timed out waiting on send operation".fmt(f), SendTimeoutError::Disconnected(..) => "sending on a disconnected channel".fmt(f), @@ -280,7 +280,7 @@ impl SendTimeoutError { } impl fmt::Display for RecvError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "receiving on an empty and disconnected channel".fmt(f) } } @@ -288,7 +288,7 @@ impl fmt::Display for RecvError { impl error::Error for RecvError {} impl fmt::Display for TryRecvError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { TryRecvError::Empty => "receiving on an empty channel".fmt(f), TryRecvError::Disconnected => "receiving on an empty and disconnected channel".fmt(f), @@ -325,7 +325,7 @@ impl TryRecvError { } impl fmt::Display for RecvTimeoutError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { RecvTimeoutError::Timeout => "timed out waiting on receive operation".fmt(f), RecvTimeoutError::Disconnected => "channel is empty and disconnected".fmt(f), @@ -362,7 +362,7 @@ impl RecvTimeoutError { } impl fmt::Display for TrySelectError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "all operations in select would block".fmt(f) } } @@ -370,7 +370,7 @@ impl fmt::Display for TrySelectError { impl error::Error for TrySelectError {} impl fmt::Display for SelectTimeoutError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "timed out waiting on select".fmt(f) } } diff --git a/crossbeam-channel/src/flavors/array.rs b/crossbeam-channel/src/flavors/array.rs index 6e0c50849..d7a6c26cc 100644 --- a/crossbeam-channel/src/flavors/array.rs +++ b/crossbeam-channel/src/flavors/array.rs @@ -143,12 +143,12 @@ impl Channel { } /// Returns a receiver handle to the channel. - pub fn receiver(&self) -> Receiver { + pub fn receiver(&self) -> Receiver<'_, T> { Receiver(self) } /// Returns a sender handle to the channel. - pub fn sender(&self) -> Sender { + pub fn sender(&self) -> Sender<'_, T> { Sender(self) } @@ -559,12 +559,12 @@ impl Drop for Channel { } /// Receiver handle to a channel. -pub struct Receiver<'a, T: 'a>(&'a Channel); +pub struct Receiver<'a, T>(&'a Channel); /// Sender handle to a channel. -pub struct Sender<'a, T: 'a>(&'a Channel); +pub struct Sender<'a, T>(&'a Channel); -impl<'a, T> SelectHandle for Receiver<'a, T> { +impl SelectHandle for Receiver<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_recv(token) } @@ -600,7 +600,7 @@ impl<'a, T> SelectHandle for Receiver<'a, T> { } } -impl<'a, T> SelectHandle for Sender<'a, T> { +impl SelectHandle for Sender<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_send(token) } diff --git a/crossbeam-channel/src/flavors/list.rs b/crossbeam-channel/src/flavors/list.rs index e4dfd82a5..532e8b6ad 100644 --- a/crossbeam-channel/src/flavors/list.rs +++ b/crossbeam-channel/src/flavors/list.rs @@ -183,12 +183,12 @@ impl Channel { } /// Returns a receiver handle to the channel. - pub fn receiver(&self) -> Receiver { + pub fn receiver(&self) -> Receiver<'_, T> { Receiver(self) } /// Returns a sender handle to the channel. - pub fn sender(&self) -> Sender { + pub fn sender(&self) -> Sender<'_, T> { Sender(self) } @@ -597,12 +597,12 @@ impl Drop for Channel { } /// Receiver handle to a channel. -pub struct Receiver<'a, T: 'a>(&'a Channel); +pub struct Receiver<'a, T>(&'a Channel); /// Sender handle to a channel. -pub struct Sender<'a, T: 'a>(&'a Channel); +pub struct Sender<'a, T>(&'a Channel); -impl<'a, T> SelectHandle for Receiver<'a, T> { +impl SelectHandle for Receiver<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_recv(token) } @@ -638,7 +638,7 @@ impl<'a, T> SelectHandle for Receiver<'a, T> { } } -impl<'a, T> SelectHandle for Sender<'a, T> { +impl SelectHandle for Sender<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_send(token) } diff --git a/crossbeam-channel/src/flavors/zero.rs b/crossbeam-channel/src/flavors/zero.rs index fbf1916d7..be647b55c 100644 --- a/crossbeam-channel/src/flavors/zero.rs +++ b/crossbeam-channel/src/flavors/zero.rs @@ -102,12 +102,12 @@ impl Channel { } /// Returns a receiver handle to the channel. - pub fn receiver(&self) -> Receiver { + pub fn receiver(&self) -> Receiver<'_, T> { Receiver(self) } /// Returns a sender handle to the channel. - pub fn sender(&self) -> Sender { + pub fn sender(&self) -> Sender<'_, T> { Sender(self) } @@ -360,12 +360,12 @@ impl Channel { } /// Receiver handle to a channel. -pub struct Receiver<'a, T: 'a>(&'a Channel); +pub struct Receiver<'a, T>(&'a Channel); /// Sender handle to a channel. -pub struct Sender<'a, T: 'a>(&'a Channel); +pub struct Sender<'a, T>(&'a Channel); -impl<'a, T> SelectHandle for Receiver<'a, T> { +impl SelectHandle for Receiver<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_recv(token) } @@ -415,7 +415,7 @@ impl<'a, T> SelectHandle for Receiver<'a, T> { } } -impl<'a, T> SelectHandle for Sender<'a, T> { +impl SelectHandle for Sender<'_, T> { fn try_select(&self, token: &mut Token) -> bool { self.0.start_send(token) } diff --git a/crossbeam-channel/src/lib.rs b/crossbeam-channel/src/lib.rs index c9092becc..e86247f42 100644 --- a/crossbeam-channel/src/lib.rs +++ b/crossbeam-channel/src/lib.rs @@ -122,8 +122,6 @@ //! It's also possible to share senders and receivers by reference: //! //! ``` -//! # extern crate crossbeam_channel; -//! # extern crate crossbeam_utils; //! # fn main() { //! use std::thread; //! use crossbeam_channel::bounded; @@ -271,12 +269,10 @@ //! An example of receiving a message from two channels: //! //! ``` -//! # #[macro_use] -//! # extern crate crossbeam_channel; //! # fn main() { //! use std::thread; //! use std::time::Duration; -//! use crossbeam_channel::unbounded; +//! use crossbeam_channel::{select, unbounded}; //! //! let (s1, r1) = unbounded(); //! let (s2, r2) = unbounded(); @@ -310,11 +306,9 @@ //! An example that prints elapsed time every 50 milliseconds for the duration of 1 second: //! //! ``` -//! # #[macro_use] -//! # extern crate crossbeam_channel; //! # fn main() { //! use std::time::{Duration, Instant}; -//! use crossbeam_channel::{after, tick}; +//! use crossbeam_channel::{after, select, tick}; //! //! let start = Instant::now(); //! let ticker = tick(Duration::from_millis(50)); @@ -344,17 +338,13 @@ //! [`Sender`]: struct.Sender.html //! [`Receiver`]: struct.Receiver.html -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] -#[macro_use] -extern crate cfg_if; +use cfg_if::cfg_if; cfg_if! { if #[cfg(feature = "std")] { - extern crate crossbeam_utils; - mod channel; mod context; mod counter; diff --git a/crossbeam-channel/src/select.rs b/crossbeam-channel/src/select.rs index c435f9e1a..b3851b770 100644 --- a/crossbeam-channel/src/select.rs +++ b/crossbeam-channel/src/select.rs @@ -119,7 +119,7 @@ pub trait SelectHandle { fn unwatch(&self, oper: Operation); } -impl<'a, T: SelectHandle> SelectHandle for &'a T { +impl SelectHandle for &T { fn try_select(&self, token: &mut Token) -> bool { (**self).try_select(token) } @@ -585,8 +585,8 @@ pub struct Select<'a> { next_index: usize, } -unsafe impl<'a> Send for Select<'a> {} -unsafe impl<'a> Sync for Select<'a> {} +unsafe impl Send for Select<'_> {} +unsafe impl Sync for Select<'_> {} impl<'a> Select<'a> { /// Creates an empty list of channel operations for selection. @@ -1017,8 +1017,8 @@ impl<'a> Default for Select<'a> { } } -impl<'a> fmt::Debug for Select<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Select<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Select { .. }") } } @@ -1049,7 +1049,7 @@ pub struct SelectedOperation<'a> { _marker: PhantomData<&'a ()>, } -impl<'a> SelectedOperation<'a> { +impl SelectedOperation<'_> { /// Returns the index of the selected operation. /// /// # Examples @@ -1153,13 +1153,13 @@ impl<'a> SelectedOperation<'a> { } } -impl<'a> fmt::Debug for SelectedOperation<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for SelectedOperation<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("SelectedOperation { .. }") } } -impl<'a> Drop for SelectedOperation<'a> { +impl Drop for SelectedOperation<'_> { fn drop(&mut self) { panic!("dropped `SelectedOperation` without completing the operation"); } diff --git a/crossbeam-channel/src/select_macro.rs b/crossbeam-channel/src/select_macro.rs index 1ecd60fda..fe6033a0d 100644 --- a/crossbeam-channel/src/select_macro.rs +++ b/crossbeam-channel/src/select_macro.rs @@ -5,10 +5,7 @@ /// This is just an ugly workaround until it becomes possible to import macros with `use` /// statements. /// -/// TODO(stjepang): Once we bump the minimum required Rust version to 1.30 or newer, we should: -/// -/// 1. Remove all `#[macro_export(local_inner_macros)]` lines. -/// 2. Replace `crossbeam_channel_delegate` with direct macro invocations. +/// TODO(stjepang): Replace `crossbeam_channel_delegate` with direct macro invocations. #[doc(hidden)] #[macro_export] macro_rules! crossbeam_channel_delegate { @@ -53,7 +50,7 @@ macro_rules! crossbeam_channel_internal { () ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($head)*) () @@ -65,7 +62,7 @@ macro_rules! crossbeam_channel_internal { (default => $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list (default() => $($tail)*) ($($head)*) @@ -76,7 +73,7 @@ macro_rules! crossbeam_channel_internal { (default -> $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected `=>` after `default` case, found `->`" )) }; @@ -85,7 +82,7 @@ macro_rules! crossbeam_channel_internal { (default $args:tt -> $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected `=>` after `default` case, found `->`" )) }; @@ -94,7 +91,7 @@ macro_rules! crossbeam_channel_internal { (recv($($args:tt)*) => $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected `->` after `recv` case, found `=>`" )) }; @@ -103,7 +100,7 @@ macro_rules! crossbeam_channel_internal { (send($($args:tt)*) => $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected `->` after `send` operation, found `=>`" )) }; @@ -112,14 +109,14 @@ macro_rules! crossbeam_channel_internal { ($case:ident $args:tt -> $res:tt -> $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error("expected `=>`, found `->`")) + $crate::crossbeam_channel_delegate!(compile_error("expected `=>`, found `->`")) }; // Print an error if there is a semicolon after the block. (@list ($case:ident $args:tt $(-> $res:pat)* => $body:block; $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "did you mean to put a comma instead of the semicolon after `}`?" )) }; @@ -128,7 +125,7 @@ macro_rules! crossbeam_channel_internal { ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr, $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list ($($tail)*) ($($head)* $case ($($args)*) $(-> $res)* => { $body },) @@ -139,7 +136,7 @@ macro_rules! crossbeam_channel_internal { ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:block $($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list ($($tail)*) ($($head)* $case ($($args)*) $(-> $res)* => { $body },) @@ -150,7 +147,7 @@ macro_rules! crossbeam_channel_internal { ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr) ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list () ($($head)* $case ($($args)*) $(-> $res)* => { $body },) @@ -161,7 +158,7 @@ macro_rules! crossbeam_channel_internal { ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr,) ($($head:tt)*) ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list () ($($head)* $case ($($args)*) $(-> $res)* => { $body },) @@ -172,216 +169,216 @@ macro_rules! crossbeam_channel_internal { ($($tail:tt)*) ($($head:tt)*) ) => { - crossbeam_channel_internal!(@list_error1 $($tail)*) + $crate::crossbeam_channel_internal!(@list_error1 $($tail)*) }; // Stage 1: check the case type. (@list_error1 recv $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error2 recv $($tail)*) + $crate::crossbeam_channel_internal!(@list_error2 recv $($tail)*) }; (@list_error1 send $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error2 send $($tail)*) + $crate::crossbeam_channel_internal!(@list_error2 send $($tail)*) }; (@list_error1 default $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error2 default $($tail)*) + $crate::crossbeam_channel_internal!(@list_error2 default $($tail)*) }; (@list_error1 $t:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected one of `recv`, `send`, or `default`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) }; (@list_error1 $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error2 $($tail)*); + $crate::crossbeam_channel_internal!(@list_error2 $($tail)*); }; // Stage 2: check the argument list. (@list_error2 $case:ident) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "missing argument list after `", - crossbeam_channel_delegate!(stringify($case)), + $crate::crossbeam_channel_delegate!(stringify($case)), "`", )) )) }; (@list_error2 $case:ident => $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "missing argument list after `", - crossbeam_channel_delegate!(stringify($case)), + $crate::crossbeam_channel_delegate!(stringify($case)), "`", )) )) }; (@list_error2 $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error3 $($tail)*) + $crate::crossbeam_channel_internal!(@list_error3 $($tail)*) }; // Stage 3: check the `=>` and what comes after it. (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "missing `=>` after `", - crossbeam_channel_delegate!(stringify($case)), + $crate::crossbeam_channel_delegate!(stringify($case)), "` case", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* =>) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected expression after `=>`" )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $body:expr; $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma instead of the semicolon after `", - crossbeam_channel_delegate!(stringify($body)), + $crate::crossbeam_channel_delegate!(stringify($body)), "`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => recv($($a:tt)*) $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected an expression after `=>`" )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => send($($a:tt)*) $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected an expression after `=>`" )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => default($($a:tt)*) $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "expected an expression after `=>`" )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $f:ident($($a:tt)*) $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma after `", - crossbeam_channel_delegate!(stringify($f)), + $crate::crossbeam_channel_delegate!(stringify($f)), "(", - crossbeam_channel_delegate!(stringify($($a)*)), + $crate::crossbeam_channel_delegate!(stringify($($a)*)), ")`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $f:ident!($($a:tt)*) $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma after `", - crossbeam_channel_delegate!(stringify($f)), + $crate::crossbeam_channel_delegate!(stringify($f)), "!(", - crossbeam_channel_delegate!(stringify($($a)*)), + $crate::crossbeam_channel_delegate!(stringify($($a)*)), ")`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $f:ident![$($a:tt)*] $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma after `", - crossbeam_channel_delegate!(stringify($f)), + $crate::crossbeam_channel_delegate!(stringify($f)), "![", - crossbeam_channel_delegate!(stringify($($a)*)), + $crate::crossbeam_channel_delegate!(stringify($($a)*)), "]`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $f:ident!{$($a:tt)*} $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma after `", - crossbeam_channel_delegate!(stringify($f)), + $crate::crossbeam_channel_delegate!(stringify($f)), "!{", - crossbeam_channel_delegate!(stringify($($a)*)), + $crate::crossbeam_channel_delegate!(stringify($($a)*)), "}`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) $(-> $r:pat)* => $body:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "did you mean to put a comma after `", - crossbeam_channel_delegate!(stringify($body)), + $crate::crossbeam_channel_delegate!(stringify($body)), "`?", )) )) }; (@list_error3 $case:ident($($args:tt)*) -> => $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error("missing pattern after `->`")) + $crate::crossbeam_channel_delegate!(compile_error("missing pattern after `->`")) }; (@list_error3 $case:ident($($args:tt)*) $t:tt $(-> $r:pat)* => $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected `->`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) }; (@list_error3 $case:ident($($args:tt)*) -> $t:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected a pattern, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) }; (@list_error3 recv($($args:tt)*) $t:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected `->`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) }; (@list_error3 send($($args:tt)*) $t:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected `->`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) }; (@list_error3 recv $args:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list after `recv`, found `", - crossbeam_channel_delegate!(stringify($args)), + $crate::crossbeam_channel_delegate!(stringify($args)), "`", )) )) }; (@list_error3 send $args:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list after `send`, found `", - crossbeam_channel_delegate!(stringify($args)), + $crate::crossbeam_channel_delegate!(stringify($args)), "`", )) )) }; (@list_error3 default $args:tt $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list or `=>` after `default`, found `", - crossbeam_channel_delegate!(stringify($args)), + $crate::crossbeam_channel_delegate!(stringify($args)), "`", )) )) }; (@list_error3 $($tail:tt)*) => { - crossbeam_channel_internal!(@list_error4 $($tail)*) + $crate::crossbeam_channel_internal!(@list_error4 $($tail)*) }; // Stage 4: fail with a generic error message. (@list_error4 $($tail:tt)*) => { - crossbeam_channel_delegate!(compile_error("invalid syntax")) + $crate::crossbeam_channel_delegate!(compile_error("invalid syntax")) }; // Success! All cases were parsed. @@ -390,7 +387,7 @@ macro_rules! crossbeam_channel_internal { $cases:tt $default:tt ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @init $cases $default @@ -403,7 +400,7 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) ($($cases)* recv($r) -> $res => $body,) @@ -416,7 +413,7 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) ($($cases)* recv($r) -> $res => $body,) @@ -429,10 +426,10 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "invalid argument list in `recv(", - crossbeam_channel_delegate!(stringify($($args)*)), + $crate::crossbeam_channel_delegate!(stringify($($args)*)), ")`", )) )) @@ -443,10 +440,10 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list after `recv`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) @@ -458,7 +455,7 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) ($($cases)* send($s, $m) -> $res => $body,) @@ -471,7 +468,7 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) ($($cases)* send($s, $m) -> $res => $body,) @@ -484,10 +481,10 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "invalid argument list in `send(", - crossbeam_channel_delegate!(stringify($($args)*)), + $crate::crossbeam_channel_delegate!(stringify($($args)*)), ")`", )) )) @@ -498,10 +495,10 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list after `send`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) @@ -513,7 +510,7 @@ macro_rules! crossbeam_channel_internal { $cases:tt () ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) $cases @@ -526,7 +523,7 @@ macro_rules! crossbeam_channel_internal { $cases:tt () ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) $cases @@ -539,7 +536,7 @@ macro_rules! crossbeam_channel_internal { $cases:tt () ) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @case ($($tail)*) $cases @@ -552,7 +549,7 @@ macro_rules! crossbeam_channel_internal { $cases:tt ($($def:tt)+) ) => { - crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(compile_error( "there can be only one `default` case in a `select!` block" )) }; @@ -562,10 +559,10 @@ macro_rules! crossbeam_channel_internal { $cases:tt $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "invalid argument list in `default(", - crossbeam_channel_delegate!(stringify($($args)*)), + $crate::crossbeam_channel_delegate!(stringify($($args)*)), ")`", )) )) @@ -576,10 +573,10 @@ macro_rules! crossbeam_channel_internal { $cases:tt $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected an argument list or `=>` after `default`, found `", - crossbeam_channel_delegate!(stringify($t)), + $crate::crossbeam_channel_delegate!(stringify($t)), "`", )) )) @@ -591,10 +588,10 @@ macro_rules! crossbeam_channel_internal { $cases:tt $default:tt ) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "expected one of `recv`, `send`, or `default`, found `", - crossbeam_channel_delegate!(stringify($case)), + $crate::crossbeam_channel_delegate!(stringify($case)), "`", )) )) @@ -760,13 +757,13 @@ macro_rules! crossbeam_channel_internal { ($($cases:tt)*) $default:tt ) => {{ - const _LEN: usize = crossbeam_channel_internal!(@count ($($cases)*)); + const _LEN: usize = $crate::crossbeam_channel_internal!(@count ($($cases)*)); let _handle: &$crate::internal::SelectHandle = &$crate::never::<()>(); #[allow(unused_mut)] let mut _sel = [(_handle, 0, ::std::ptr::null()); _LEN]; - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @add _sel ($($cases)*) @@ -814,7 +811,7 @@ macro_rules! crossbeam_channel_internal { 0 }; (@count ($oper:ident $args:tt -> $res:pat => $body:tt, $($cases:tt)*)) => { - 1 + crossbeam_channel_internal!(@count ($($cases)*)) + 1 + $crate::crossbeam_channel_internal!(@count ($($cases)*)) }; // Run blocking selection. @@ -832,7 +829,7 @@ macro_rules! crossbeam_channel_internal { unsafe { ::std::mem::transmute(_oper) } }; - crossbeam_channel_internal! { + $crate::crossbeam_channel_internal! { @complete $sel _oper @@ -860,7 +857,7 @@ macro_rules! crossbeam_channel_internal { $body } Some(_oper) => { - crossbeam_channel_internal! { + $crate::crossbeam_channel_internal! { @complete $sel _oper @@ -890,7 +887,7 @@ macro_rules! crossbeam_channel_internal { $body } ::std::option::Option::Some(_oper) => { - crossbeam_channel_internal! { + $crate::crossbeam_channel_internal! { @complete $sel _oper @@ -907,7 +904,7 @@ macro_rules! crossbeam_channel_internal { () $cases:tt ) => { - crossbeam_channel_delegate!(compile_error("too many operations in a `select!` block")) + $crate::crossbeam_channel_delegate!(compile_error("too many operations in a `select!` block")) }; // Add a receive operation to `sel`. (@add @@ -930,7 +927,7 @@ macro_rules! crossbeam_channel_internal { }; $sel[$i] = ($var, $i, $var as *const $crate::Receiver<_> as *const u8); - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @add $sel ($($tail)*) @@ -962,7 +959,7 @@ macro_rules! crossbeam_channel_internal { }; $sel[$i] = ($var, $i, $var as *const $crate::Sender<_> as *const u8); - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @add $sel ($($tail)*) @@ -987,7 +984,7 @@ macro_rules! crossbeam_channel_internal { let $res = _res; $body } else { - crossbeam_channel_internal! { + $crate::crossbeam_channel_internal! { @complete $sel $oper @@ -1008,7 +1005,7 @@ macro_rules! crossbeam_channel_internal { let $res = _res; $body } else { - crossbeam_channel_internal! { + $crate::crossbeam_channel_internal! { @complete $sel $oper @@ -1022,34 +1019,34 @@ macro_rules! crossbeam_channel_internal { $oper:ident () ) => {{ - crossbeam_channel_delegate!(unreachable( + $crate::crossbeam_channel_delegate!(unreachable( "internal error in crossbeam-channel: invalid case" )) }}; // Catches a bug within this macro (should not happen). (@$($tokens:tt)*) => { - crossbeam_channel_delegate!(compile_error( - crossbeam_channel_delegate!(concat( + $crate::crossbeam_channel_delegate!(compile_error( + $crate::crossbeam_channel_delegate!(concat( "internal error in crossbeam-channel: ", - crossbeam_channel_delegate!(stringify(@$($tokens)*)), + $crate::crossbeam_channel_delegate!(stringify(@$($tokens)*)), )) )) }; // The entry points. () => { - crossbeam_channel_delegate!(compile_error("empty `select!` block")) + $crate::crossbeam_channel_delegate!(compile_error("empty `select!` block")) }; ($($case:ident $(($($args:tt)*))* => $body:expr $(,)*)*) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list ($($case $(($($args)*))* => { $body },)*) () ) }; ($($tokens:tt)*) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( @list ($($tokens)*) () @@ -1079,11 +1076,9 @@ macro_rules! crossbeam_channel_internal { /// Block until a send or a receive operation is selected: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::thread; -/// use crossbeam_channel::unbounded; +/// use crossbeam_channel::{select, unbounded}; /// /// let (s1, r1) = unbounded(); /// let (s2, r2) = unbounded(); @@ -1103,12 +1098,10 @@ macro_rules! crossbeam_channel_internal { /// Select from a set of operations without blocking: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::thread; /// use std::time::Duration; -/// use crossbeam_channel::unbounded; +/// use crossbeam_channel::{select, unbounded}; /// /// let (s1, r1) = unbounded(); /// let (s2, r2) = unbounded(); @@ -1134,12 +1127,10 @@ macro_rules! crossbeam_channel_internal { /// Select over a set of operations with a timeout: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::thread; /// use std::time::Duration; -/// use crossbeam_channel::unbounded; +/// use crossbeam_channel::{select, unbounded}; /// /// let (s1, r1) = unbounded(); /// let (s2, r2) = unbounded(); @@ -1165,12 +1156,10 @@ macro_rules! crossbeam_channel_internal { /// Optionally add a receive operation to `select!` using [`never`]: /// /// ``` -/// # #[macro_use] -/// # extern crate crossbeam_channel; /// # fn main() { /// use std::thread; /// use std::time::Duration; -/// use crossbeam_channel::{never, unbounded}; +/// use crossbeam_channel::{select, never, unbounded}; /// /// let (s1, r1) = unbounded(); /// let (s2, r2) = unbounded(); @@ -1202,7 +1191,7 @@ macro_rules! crossbeam_channel_internal { #[macro_export(local_inner_macros)] macro_rules! select { ($($tokens:tt)*) => { - crossbeam_channel_internal!( + $crate::crossbeam_channel_internal!( $($tokens)* ) }; diff --git a/crossbeam-channel/src/utils.rs b/crossbeam-channel/src/utils.rs index c6513bc3f..502f76816 100644 --- a/crossbeam-channel/src/utils.rs +++ b/crossbeam-channel/src/utils.rs @@ -87,17 +87,17 @@ impl Spinlock { } /// A guard holding a spinlock locked. -pub struct SpinlockGuard<'a, T: 'a> { +pub struct SpinlockGuard<'a, T> { parent: &'a Spinlock, } -impl<'a, T> Drop for SpinlockGuard<'a, T> { +impl Drop for SpinlockGuard<'_, T> { fn drop(&mut self) { self.parent.flag.store(false, Ordering::Release); } } -impl<'a, T> Deref for SpinlockGuard<'a, T> { +impl Deref for SpinlockGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -105,7 +105,7 @@ impl<'a, T> Deref for SpinlockGuard<'a, T> { } } -impl<'a, T> DerefMut for SpinlockGuard<'a, T> { +impl DerefMut for SpinlockGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.parent.value.get() } } diff --git a/crossbeam-channel/tests/after.rs b/crossbeam-channel/tests/after.rs index 1137bb1b7..20670dc5a 100644 --- a/crossbeam-channel/tests/after.rs +++ b/crossbeam-channel/tests/after.rs @@ -1,16 +1,11 @@ //! Tests for the after channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate rand; - use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::thread; use std::time::{Duration, Instant}; -use crossbeam_channel::{after, Select, TryRecvError}; +use crossbeam_channel::{after, select, Select, TryRecvError}; use crossbeam_utils::thread::scope; fn ms(ms: u64) -> Duration { diff --git a/crossbeam-channel/tests/array.rs b/crossbeam-channel/tests/array.rs index a6fc8451b..a7ae323d9 100644 --- a/crossbeam-channel/tests/array.rs +++ b/crossbeam-channel/tests/array.rs @@ -1,17 +1,12 @@ //! Tests for the array channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate rand; - use std::any::Any; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; -use crossbeam_channel::{bounded, Receiver}; +use crossbeam_channel::{bounded, select, Receiver}; use crossbeam_channel::{RecvError, RecvTimeoutError, TryRecvError}; use crossbeam_channel::{SendError, SendTimeoutError, TrySendError}; use crossbeam_utils::thread::scope; diff --git a/crossbeam-channel/tests/golang.rs b/crossbeam-channel/tests/golang.rs index b1230fd11..e999aea36 100644 --- a/crossbeam-channel/tests/golang.rs +++ b/crossbeam-channel/tests/golang.rs @@ -9,9 +9,6 @@ //! - https://golang.org/LICENSE //! - https://golang.org/PATENTS -#[macro_use] -extern crate crossbeam_channel; - use std::any::Any; use std::cell::Cell; use std::collections::HashMap; @@ -19,7 +16,7 @@ use std::sync::{Arc, Condvar, Mutex}; use std::thread; use std::time::Duration; -use crossbeam_channel::{bounded, tick, Receiver, Select, Sender}; +use crossbeam_channel::{bounded, select, tick, Receiver, Select, Sender}; fn ms(ms: u64) -> Duration { Duration::from_millis(ms) diff --git a/crossbeam-channel/tests/iter.rs b/crossbeam-channel/tests/iter.rs index 6acec59c2..38bcac2f0 100644 --- a/crossbeam-channel/tests/iter.rs +++ b/crossbeam-channel/tests/iter.rs @@ -1,8 +1,5 @@ //! Tests for iteration over receivers. -extern crate crossbeam_channel; -extern crate crossbeam_utils; - use crossbeam_channel::unbounded; use crossbeam_utils::thread::scope; diff --git a/crossbeam-channel/tests/list.rs b/crossbeam-channel/tests/list.rs index ed1d4c420..8b8410540 100644 --- a/crossbeam-channel/tests/list.rs +++ b/crossbeam-channel/tests/list.rs @@ -1,17 +1,12 @@ //! Tests for the list channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate rand; - use std::any::Any; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; -use crossbeam_channel::{unbounded, Receiver}; +use crossbeam_channel::{select, unbounded, Receiver}; use crossbeam_channel::{RecvError, RecvTimeoutError, TryRecvError}; use crossbeam_channel::{SendError, SendTimeoutError, TrySendError}; use crossbeam_utils::thread::scope; diff --git a/crossbeam-channel/tests/mpsc.rs b/crossbeam-channel/tests/mpsc.rs index 4851f9ee3..2a0786a71 100644 --- a/crossbeam-channel/tests/mpsc.rs +++ b/crossbeam-channel/tests/mpsc.rs @@ -20,14 +20,13 @@ //! - https://github.com/rust-lang/rust/blob/master/COPYRIGHT //! - https://www.rust-lang.org/en-US/legal.html -#[macro_use] -extern crate crossbeam_channel as cc; - use std::sync::mpsc::{RecvError, RecvTimeoutError, TryRecvError}; use std::sync::mpsc::{SendError, TrySendError}; use std::thread::JoinHandle; use std::time::Duration; +use crossbeam_channel as cc; + pub struct Sender { pub inner: cc::Sender, } @@ -175,7 +174,7 @@ macro_rules! select { ( $($name:pat = $rx:ident.$meth:ident() => $code:expr),+ ) => ({ - crossbeam_channel_internal! { + cc::crossbeam_channel_internal! { $( recv(($rx).inner) -> res => { let $name = res.map_err(|_| ::std::sync::mpsc::RecvError); diff --git a/crossbeam-channel/tests/never.rs b/crossbeam-channel/tests/never.rs index 35b6f74dd..31cebf67d 100644 --- a/crossbeam-channel/tests/never.rs +++ b/crossbeam-channel/tests/never.rs @@ -1,13 +1,9 @@ //! Tests for the never channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate rand; - use std::thread; use std::time::{Duration, Instant}; -use crossbeam_channel::{never, tick, unbounded}; +use crossbeam_channel::{never, select, tick, unbounded}; fn ms(ms: u64) -> Duration { Duration::from_millis(ms) diff --git a/crossbeam-channel/tests/ready.rs b/crossbeam-channel/tests/ready.rs index 340379413..700f487e0 100644 --- a/crossbeam-channel/tests/ready.rs +++ b/crossbeam-channel/tests/ready.rs @@ -1,8 +1,5 @@ //! Tests for channel readiness using the `Select` struct. -extern crate crossbeam_channel; -extern crate crossbeam_utils; - use std::any::Any; use std::cell::Cell; use std::thread; diff --git a/crossbeam-channel/tests/same_channel.rs b/crossbeam-channel/tests/same_channel.rs index 8e34faf44..da4c8f3e7 100644 --- a/crossbeam-channel/tests/same_channel.rs +++ b/crossbeam-channel/tests/same_channel.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_channel; - use std::time::Duration; use crossbeam_channel::{after, bounded, never, tick, unbounded}; diff --git a/crossbeam-channel/tests/select.rs b/crossbeam-channel/tests/select.rs index b18d66d7c..4cf08b6a6 100644 --- a/crossbeam-channel/tests/select.rs +++ b/crossbeam-channel/tests/select.rs @@ -1,8 +1,5 @@ //! Tests for channel selection using the `Select` struct. -extern crate crossbeam_channel; -extern crate crossbeam_utils; - use std::any::Any; use std::cell::Cell; use std::thread; diff --git a/crossbeam-channel/tests/select_macro.rs b/crossbeam-channel/tests/select_macro.rs index 8d3913f60..c05f7a0e6 100644 --- a/crossbeam-channel/tests/select_macro.rs +++ b/crossbeam-channel/tests/select_macro.rs @@ -2,17 +2,13 @@ #![forbid(unsafe_code)] // select! is safe. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; - use std::any::Any; use std::cell::Cell; use std::ops::Deref; use std::thread; use std::time::{Duration, Instant}; -use crossbeam_channel::{after, bounded, never, tick, unbounded}; +use crossbeam_channel::{after, bounded, never, select, tick, unbounded}; use crossbeam_channel::{Receiver, RecvError, SendError, Sender, TryRecvError}; use crossbeam_utils::thread::scope; diff --git a/crossbeam-channel/tests/thread_locals.rs b/crossbeam-channel/tests/thread_locals.rs index fd319c728..9e27146df 100644 --- a/crossbeam-channel/tests/thread_locals.rs +++ b/crossbeam-channel/tests/thread_locals.rs @@ -1,13 +1,9 @@ //! Tests that make sure accessing thread-locals while exiting the thread doesn't cause panics. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; - use std::thread; use std::time::Duration; -use crossbeam_channel::unbounded; +use crossbeam_channel::{select, unbounded}; use crossbeam_utils::thread::scope; fn ms(ms: u64) -> Duration { diff --git a/crossbeam-channel/tests/tick.rs b/crossbeam-channel/tests/tick.rs index 34e55b31b..5dc87306f 100644 --- a/crossbeam-channel/tests/tick.rs +++ b/crossbeam-channel/tests/tick.rs @@ -1,16 +1,11 @@ //! Tests for the tick channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate rand; - use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::thread; use std::time::{Duration, Instant}; -use crossbeam_channel::{after, tick, Select, TryRecvError}; +use crossbeam_channel::{after, select, tick, Select, TryRecvError}; use crossbeam_utils::thread::scope; fn ms(ms: u64) -> Duration { diff --git a/crossbeam-channel/tests/zero.rs b/crossbeam-channel/tests/zero.rs index bd336ee15..66dcc1eeb 100644 --- a/crossbeam-channel/tests/zero.rs +++ b/crossbeam-channel/tests/zero.rs @@ -1,17 +1,12 @@ //! Tests for the zero channel flavor. -#[macro_use] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate rand; - use std::any::Any; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; -use crossbeam_channel::{bounded, Receiver}; +use crossbeam_channel::{bounded, select, Receiver}; use crossbeam_channel::{RecvError, RecvTimeoutError, TryRecvError}; use crossbeam_channel::{SendError, SendTimeoutError, TrySendError}; use crossbeam_utils::thread::scope; diff --git a/crossbeam-deque/README.md b/crossbeam-deque/README.md index 28c88d47b..9f3be8436 100644 --- a/crossbeam-deque/README.md +++ b/crossbeam-deque/README.md @@ -24,12 +24,6 @@ Add this to your `Cargo.toml`: crossbeam-deque = "0.7" ``` -Next, add this to your crate: - -```rust -extern crate crossbeam_deque; -``` - ## Compatibility Crossbeam Deque supports stable Rust releases going back at least six months, diff --git a/crossbeam-deque/src/deque.rs b/crossbeam-deque/src/deque.rs index c08735b95..907dd0c29 100644 --- a/crossbeam-deque/src/deque.rs +++ b/crossbeam-deque/src/deque.rs @@ -8,7 +8,7 @@ use std::ptr; use std::sync::atomic::{self, AtomicIsize, AtomicPtr, AtomicUsize, Ordering}; use std::sync::Arc; -use crate::epoch::{Atomic, Owned}; +use crate::epoch::{self, Atomic, Owned}; use crate::utils::{Backoff, CachePadded}; // Minimum buffer capacity. @@ -532,7 +532,7 @@ impl Worker { } impl fmt::Debug for Worker { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Worker { .. }") } } @@ -1040,7 +1040,7 @@ impl Clone for Stealer { } impl fmt::Debug for Stealer { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Stealer { .. }") } } @@ -1798,7 +1798,7 @@ impl Drop for Injector { } impl fmt::Debug for Injector { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Worker { .. }") } } @@ -1951,7 +1951,7 @@ impl Steal { } impl fmt::Debug for Steal { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Steal::Empty => f.pad("Empty"), Steal::Success(_) => f.pad("Success(..)"), diff --git a/crossbeam-deque/src/lib.rs b/crossbeam-deque/src/lib.rs index 901309a6f..4195c1aed 100644 --- a/crossbeam-deque/src/lib.rs +++ b/crossbeam-deque/src/lib.rs @@ -86,17 +86,15 @@ //! [`steal_batch()`]: struct.Stealer.html#method.steal_batch //! [`steal_batch_and_pop()`]: struct.Stealer.html#method.steal_batch_and_pop -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] -#[macro_use] -extern crate cfg_if; +use cfg_if::cfg_if; cfg_if! { if #[cfg(feature = "std")] { - extern crate crossbeam_epoch as epoch; - extern crate crossbeam_utils as utils; + use crossbeam_epoch as epoch; + use crossbeam_utils as utils; mod deque; pub use crate::deque::{Injector, Steal, Stealer, Worker}; diff --git a/crossbeam-deque/tests/fifo.rs b/crossbeam-deque/tests/fifo.rs index 96be08bb3..19a1f5849 100644 --- a/crossbeam-deque/tests/fifo.rs +++ b/crossbeam-deque/tests/fifo.rs @@ -1,15 +1,11 @@ -extern crate crossbeam_deque as deque; -extern crate crossbeam_utils as utils; -extern crate rand; - use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::sync::{Arc, Mutex}; -use crate::deque::Steal::{Empty, Success}; -use crate::deque::Worker; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::Worker; +use crossbeam_utils::thread::scope; use rand::Rng; -use crate::utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/injector.rs b/crossbeam-deque/tests/injector.rs index b5965724d..0165e1a6b 100644 --- a/crossbeam-deque/tests/injector.rs +++ b/crossbeam-deque/tests/injector.rs @@ -1,15 +1,11 @@ -extern crate crossbeam_deque as deque; -extern crate crossbeam_utils as utils; -extern crate rand; - use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::sync::{Arc, Mutex}; -use crate::deque::Steal::{Empty, Success}; -use crate::deque::{Injector, Worker}; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::{Injector, Worker}; +use crossbeam_utils::thread::scope; use rand::Rng; -use crate::utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/lifo.rs b/crossbeam-deque/tests/lifo.rs index ac4882041..d7e498add 100644 --- a/crossbeam-deque/tests/lifo.rs +++ b/crossbeam-deque/tests/lifo.rs @@ -1,15 +1,11 @@ -extern crate crossbeam_deque as deque; -extern crate crossbeam_utils as utils; -extern crate rand; - use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::sync::{Arc, Mutex}; -use crate::deque::Steal::{Empty, Success}; -use crate::deque::Worker; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::Worker; +use crossbeam_utils::thread::scope; use rand::Rng; -use crate::utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/steal.rs b/crossbeam-deque/tests/steal.rs index f69ea829f..af2499856 100644 --- a/crossbeam-deque/tests/steal.rs +++ b/crossbeam-deque/tests/steal.rs @@ -1,7 +1,5 @@ -extern crate crossbeam_deque as deque; - -use crate::deque::Steal::Success; -use crate::deque::{Injector, Worker}; +use crossbeam_deque::Steal::Success; +use crossbeam_deque::{Injector, Worker}; #[test] fn steal_fifo() { diff --git a/crossbeam-epoch/README.md b/crossbeam-epoch/README.md index fd6dba778..61e813890 100644 --- a/crossbeam-epoch/README.md +++ b/crossbeam-epoch/README.md @@ -31,12 +31,6 @@ Add this to your `Cargo.toml`: crossbeam-epoch = "0.8" ``` -Next, add this to your crate: - -```rust -extern crate crossbeam_epoch as epoch; -``` - ## Compatibility Crossbeam Epoch supports stable Rust releases going back at least six months, diff --git a/crossbeam-epoch/benches/defer.rs b/crossbeam-epoch/benches/defer.rs index a77c2d3ba..246f90798 100644 --- a/crossbeam-epoch/benches/defer.rs +++ b/crossbeam-epoch/benches/defer.rs @@ -1,12 +1,10 @@ #![feature(test)] -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_utils as utils; extern crate test; -use crate::epoch::Owned; +use crossbeam_epoch::{self as epoch, Owned}; +use crossbeam_utils::thread::scope; use test::Bencher; -use crate::utils::thread::scope; #[bench] fn single_alloc_defer_free(b: &mut Bencher) { diff --git a/crossbeam-epoch/benches/flush.rs b/crossbeam-epoch/benches/flush.rs index 6a3701eab..99aab19e1 100644 --- a/crossbeam-epoch/benches/flush.rs +++ b/crossbeam-epoch/benches/flush.rs @@ -1,13 +1,12 @@ #![feature(test)] -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_utils as utils; extern crate test; use std::sync::Barrier; +use crossbeam_epoch as epoch; +use crossbeam_utils::thread::scope; use test::Bencher; -use crate::utils::thread::scope; #[bench] fn single_flush(b: &mut Bencher) { diff --git a/crossbeam-epoch/benches/pin.rs b/crossbeam-epoch/benches/pin.rs index 6c0cb6647..0dff4c596 100644 --- a/crossbeam-epoch/benches/pin.rs +++ b/crossbeam-epoch/benches/pin.rs @@ -1,11 +1,10 @@ #![feature(test)] -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_utils as utils; extern crate test; +use crossbeam_epoch as epoch; +use crossbeam_utils::thread::scope; use test::Bencher; -use crate::utils::thread::scope; #[bench] fn single_pin(b: &mut Bencher) { diff --git a/crossbeam-epoch/examples/sanitize.rs b/crossbeam-epoch/examples/sanitize.rs index ad39b8786..5110f8af4 100644 --- a/crossbeam-epoch/examples/sanitize.rs +++ b/crossbeam-epoch/examples/sanitize.rs @@ -1,13 +1,10 @@ -extern crate crossbeam_epoch as epoch; -extern crate rand; - use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed}; use std::sync::Arc; use std::thread; use std::time::{Duration, Instant}; -use crate::epoch::{Atomic, Collector, LocalHandle, Owned, Shared}; +use crossbeam_epoch::{self as epoch, Atomic, Collector, LocalHandle, Owned, Shared}; use rand::Rng; fn worker(a: Arc>, handle: LocalHandle) -> usize { diff --git a/crossbeam-epoch/examples/treiber_stack.rs b/crossbeam-epoch/examples/treiber_stack.rs index 11d3919eb..a2c3c16ff 100644 --- a/crossbeam-epoch/examples/treiber_stack.rs +++ b/crossbeam-epoch/examples/treiber_stack.rs @@ -1,12 +1,9 @@ -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_utils as utils; - use std::mem::ManuallyDrop; use std::ptr; use std::sync::atomic::Ordering::{Acquire, Relaxed, Release}; -use crate::epoch::{Atomic, Owned}; -use crate::utils::thread::scope; +use crossbeam_epoch::{self as epoch, Atomic, Owned}; +use crossbeam_utils::thread::scope; /// Treiber's lock-free stack. /// diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index 108948594..579d960a8 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -8,8 +8,8 @@ use core::ops::{Deref, DerefMut}; use core::ptr; use core::sync::atomic::{AtomicUsize, Ordering}; -use crossbeam_utils::atomic::AtomicConsume; use crate::guard::Guard; +use crossbeam_utils::atomic::AtomicConsume; /// Given ordering for the success case in a compare-exchange operation, returns the strongest /// appropriate ordering for the failure case. @@ -24,7 +24,7 @@ fn strongest_failure_ordering(ord: Ordering) -> Ordering { } /// The error returned on failed compare-and-set operation. -pub struct CompareAndSetError<'g, T: 'g, P: Pointer> { +pub struct CompareAndSetError<'g, T, P: Pointer> { /// The value in the atomic pointer at the time of the failed operation. pub current: Shared<'g, T>, @@ -33,7 +33,7 @@ pub struct CompareAndSetError<'g, T: 'g, P: Pointer> { } impl<'g, T: 'g, P: Pointer + fmt::Debug> fmt::Debug for CompareAndSetError<'g, T, P> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("CompareAndSetError") .field("current", &self.current) .field("new", &self.new) @@ -287,7 +287,7 @@ impl Atomic { /// ``` pub fn compare_and_set<'g, O, P>( &self, - current: Shared, + current: Shared<'_, T>, new: P, ord: O, _: &'g Guard, @@ -357,7 +357,7 @@ impl Atomic { /// ``` pub fn compare_and_set_weak<'g, O, P>( &self, - current: Shared, + current: Shared<'_, T>, new: P, ord: O, _: &'g Guard, @@ -493,7 +493,7 @@ impl Atomic { } impl fmt::Debug for Atomic { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let data = self.data.load(Ordering::SeqCst); let (raw, tag) = decompose_data::(data); @@ -505,7 +505,7 @@ impl fmt::Debug for Atomic { } impl fmt::Pointer for Atomic { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let data = self.data.load(Ordering::SeqCst); let (raw, _) = decompose_data::(data); fmt::Pointer::fmt(&raw, f) @@ -745,7 +745,7 @@ impl Drop for Owned { } impl fmt::Debug for Owned { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (raw, tag) = decompose_data::(self.data); f.debug_struct("Owned") @@ -837,7 +837,7 @@ pub struct Shared<'g, T: 'g> { _marker: PhantomData<(&'g (), *const T)>, } -impl<'g, T> Clone for Shared<'g, T> { +impl Clone for Shared<'_, T> { fn clone(&self) -> Self { Shared { data: self.data, @@ -846,9 +846,9 @@ impl<'g, T> Clone for Shared<'g, T> { } } -impl<'g, T> Copy for Shared<'g, T> {} +impl Copy for Shared<'_, T> {} -impl<'g, T> Pointer for Shared<'g, T> { +impl Pointer for Shared<'_, T> { #[inline] fn into_usize(self) -> usize { self.data @@ -1103,7 +1103,7 @@ impl<'g, T> Shared<'g, T> { } } -impl<'g, T> From<*const T> for Shared<'g, T> { +impl From<*const T> for Shared<'_, T> { /// Returns a new pointer pointing to `raw`. /// /// # Panics @@ -1130,7 +1130,7 @@ impl<'g, T> PartialEq> for Shared<'g, T> { } } -impl<'g, T> Eq for Shared<'g, T> {} +impl Eq for Shared<'_, T> {} impl<'g, T> PartialOrd> for Shared<'g, T> { fn partial_cmp(&self, other: &Self) -> Option { @@ -1138,14 +1138,14 @@ impl<'g, T> PartialOrd> for Shared<'g, T> { } } -impl<'g, T> Ord for Shared<'g, T> { +impl Ord for Shared<'_, T> { fn cmp(&self, other: &Self) -> cmp::Ordering { self.data.cmp(&other.data) } } -impl<'g, T> fmt::Debug for Shared<'g, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Shared<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (raw, tag) = decompose_data::(self.data); f.debug_struct("Shared") @@ -1155,13 +1155,13 @@ impl<'g, T> fmt::Debug for Shared<'g, T> { } } -impl<'g, T> fmt::Pointer for Shared<'g, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Pointer for Shared<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Pointer::fmt(&self.as_raw(), f) } } -impl<'g, T> Default for Shared<'g, T> { +impl Default for Shared<'_, T> { fn default() -> Self { Shared::null() } diff --git a/crossbeam-epoch/src/collector.rs b/crossbeam-epoch/src/collector.rs index d5697eab8..50ef96830 100644 --- a/crossbeam-epoch/src/collector.rs +++ b/crossbeam-epoch/src/collector.rs @@ -50,7 +50,7 @@ impl Clone for Collector { } impl fmt::Debug for Collector { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Collector { .. }") } } @@ -98,7 +98,7 @@ impl Drop for LocalHandle { } impl fmt::Debug for LocalHandle { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("LocalHandle { .. }") } } diff --git a/crossbeam-epoch/src/default.rs b/crossbeam-epoch/src/default.rs index 4d58ea6f1..1deac2114 100644 --- a/crossbeam-epoch/src/default.rs +++ b/crossbeam-epoch/src/default.rs @@ -6,6 +6,7 @@ use crate::collector::{Collector, LocalHandle}; use crate::guard::Guard; +use lazy_static::lazy_static; lazy_static! { /// The global data for the default garbage collector. diff --git a/crossbeam-epoch/src/deferred.rs b/crossbeam-epoch/src/deferred.rs index 4f620de92..089798b89 100644 --- a/crossbeam-epoch/src/deferred.rs +++ b/crossbeam-epoch/src/deferred.rs @@ -23,7 +23,7 @@ pub struct Deferred { } impl fmt::Debug for Deferred { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { f.pad("Deferred { .. }") } } diff --git a/crossbeam-epoch/src/guard.rs b/crossbeam-epoch/src/guard.rs index 04018caa1..aa470e4dc 100644 --- a/crossbeam-epoch/src/guard.rs +++ b/crossbeam-epoch/src/guard.rs @@ -1,6 +1,8 @@ use core::fmt; use core::mem; +use scopeguard::defer; + use crate::atomic::Shared; use crate::collector::Collector; use crate::deferred::Deferred; @@ -268,7 +270,7 @@ impl Guard { /// ``` /// /// [`unprotected`]: fn.unprotected.html - pub unsafe fn defer_destroy(&self, ptr: Shared) { + pub unsafe fn defer_destroy(&self, ptr: Shared<'_, T>) { self.defer_unchecked(move || ptr.into_owned()); } @@ -426,7 +428,7 @@ impl Drop for Guard { } impl fmt::Debug for Guard { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Guard { .. }") } } diff --git a/crossbeam-epoch/src/internal.rs b/crossbeam-epoch/src/internal.rs index 7a7445aa4..b30038734 100644 --- a/crossbeam-epoch/src/internal.rs +++ b/crossbeam-epoch/src/internal.rs @@ -43,6 +43,7 @@ use core::sync::atomic::Ordering; use core::{fmt, ptr}; use crossbeam_utils::CachePadded; +use memoffset::offset_of; use crate::atomic::{Owned, Shared}; use crate::collector::{Collector, LocalHandle}; @@ -205,7 +206,7 @@ impl Drop for Bag { // can't #[derive(Debug)] because Debug is not implemented for arrays 64 items long impl fmt::Debug for Bag { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Bag") .field("deferreds", &&self.deferreds[..self.len]) .finish() diff --git a/crossbeam-epoch/src/lib.rs b/crossbeam-epoch/src/lib.rs index cd05c5d88..1d4a665d3 100644 --- a/crossbeam-epoch/src/lib.rs +++ b/crossbeam-epoch/src/lib.rs @@ -54,26 +54,16 @@ //! [`pin`]: fn.pin.html //! [`defer`]: struct.Guard.html#method.defer -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] -#[macro_use] -extern crate cfg_if; -#[cfg(feature = "alloc")] -extern crate alloc; -#[cfg(feature = "std")] -extern crate core; +use cfg_if::cfg_if; #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] cfg_if! { if #[cfg(feature = "alloc")] { - extern crate crossbeam_utils; - #[macro_use] - extern crate memoffset; - #[macro_use] - extern crate scopeguard; + extern crate alloc; mod atomic; mod collector; @@ -91,9 +81,6 @@ cfg_if! { cfg_if! { if #[cfg(feature = "std")] { - #[macro_use] - extern crate lazy_static; - mod default; pub use self::default::{default_collector, is_pinned, pin}; } diff --git a/crossbeam-epoch/src/sync/list.rs b/crossbeam-epoch/src/sync/list.rs index aa13c6806..57aea92f9 100644 --- a/crossbeam-epoch/src/sync/list.rs +++ b/crossbeam-epoch/src/sync/list.rs @@ -102,7 +102,7 @@ pub struct List = T> { } /// An iterator used for retrieving values from the list. -pub struct Iter<'g, T: 'g, C: IsElement> { +pub struct Iter<'g, T, C: IsElement> { /// The guard that protects the iteration. guard: &'g Guard, @@ -298,9 +298,9 @@ impl<'g, T: 'g, C: IsElement> Iterator for Iter<'g, T, C> { #[cfg(test)] mod tests { use super::*; + use crate::{Collector, Owned}; use crossbeam_utils::thread; use std::sync::Barrier; - use crate::{Collector, Owned}; impl IsElement for Entry { fn entry_of(entry: &Entry) -> &Entry { diff --git a/crossbeam-epoch/src/sync/queue.rs b/crossbeam-epoch/src/sync/queue.rs index 3cc4a5ac3..98ef667b5 100644 --- a/crossbeam-epoch/src/sync/queue.rs +++ b/crossbeam-epoch/src/sync/queue.rs @@ -63,7 +63,7 @@ impl Queue { /// Attempts to atomically place `n` into the `next` pointer of `onto`, and returns `true` on /// success. The queue's `tail` pointer may be updated. #[inline(always)] - fn push_internal(&self, onto: Shared>, new: Shared>, guard: &Guard) -> bool { + fn push_internal(&self, onto: Shared<'_, Node>, new: Shared<'_, Node>, guard: &Guard) -> bool { // is `onto` the actual tail? let o = unsafe { onto.deref() }; let next = o.next.load(Acquire, guard); diff --git a/crossbeam-queue/README.md b/crossbeam-queue/README.md index 2735aca0b..bbc17cce5 100644 --- a/crossbeam-queue/README.md +++ b/crossbeam-queue/README.md @@ -29,12 +29,6 @@ Add this to your `Cargo.toml`: crossbeam-queue = "0.2" ``` -Next, add this to your crate: - -```rust -extern crate crossbeam_queue; -``` - ## Compatibility Crossbeam Queue supports stable Rust releases going back at least six months, diff --git a/crossbeam-queue/src/array_queue.rs b/crossbeam-queue/src/array_queue.rs index 246ab0ebe..c27e196c8 100644 --- a/crossbeam-queue/src/array_queue.rs +++ b/crossbeam-queue/src/array_queue.rs @@ -431,7 +431,7 @@ impl Drop for ArrayQueue { } impl fmt::Debug for ArrayQueue { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("ArrayQueue { .. }") } } diff --git a/crossbeam-queue/src/err.rs b/crossbeam-queue/src/err.rs index 7b9757e8e..44fe916c3 100644 --- a/crossbeam-queue/src/err.rs +++ b/crossbeam-queue/src/err.rs @@ -5,13 +5,13 @@ use core::fmt; pub struct PopError; impl fmt::Debug for PopError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "PopError".fmt(f) } } impl fmt::Display for PopError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "popping from an empty queue".fmt(f) } } @@ -24,13 +24,13 @@ impl ::std::error::Error for PopError {} pub struct PushError(pub T); impl fmt::Debug for PushError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "PushError(..)".fmt(f) } } impl fmt::Display for PushError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "pushing into a full queue".fmt(f) } } diff --git a/crossbeam-queue/src/lib.rs b/crossbeam-queue/src/lib.rs index 878728aa4..76175bb13 100644 --- a/crossbeam-queue/src/lib.rs +++ b/crossbeam-queue/src/lib.rs @@ -8,24 +8,15 @@ //! [`ArrayQueue`]: struct.ArrayQueue.html //! [`SegQueue`]: struct.SegQueue.html -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] -#[macro_use] -extern crate cfg_if; -#[cfg(feature = "alloc")] -extern crate alloc; -#[cfg(feature = "std")] -extern crate core; - -extern crate crossbeam_utils; - -#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] -cfg_if! { +cfg_if::cfg_if! { if #[cfg(feature = "alloc")] { + extern crate alloc; + mod array_queue; mod err; mod seg_queue; diff --git a/crossbeam-queue/src/seg_queue.rs b/crossbeam-queue/src/seg_queue.rs index d5bb7bb05..2ddbc5ef4 100644 --- a/crossbeam-queue/src/seg_queue.rs +++ b/crossbeam-queue/src/seg_queue.rs @@ -476,7 +476,7 @@ impl Drop for SegQueue { } impl fmt::Debug for SegQueue { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("SegQueue { .. }") } } diff --git a/crossbeam-queue/tests/array_queue.rs b/crossbeam-queue/tests/array_queue.rs index a4f64f343..6dd6ce277 100644 --- a/crossbeam-queue/tests/array_queue.rs +++ b/crossbeam-queue/tests/array_queue.rs @@ -1,7 +1,3 @@ -extern crate crossbeam_queue; -extern crate crossbeam_utils; -extern crate rand; - use std::sync::atomic::{AtomicUsize, Ordering}; use crossbeam_queue::ArrayQueue; diff --git a/crossbeam-queue/tests/seg_queue.rs b/crossbeam-queue/tests/seg_queue.rs index ec32e1f64..b8ffbd3b3 100644 --- a/crossbeam-queue/tests/seg_queue.rs +++ b/crossbeam-queue/tests/seg_queue.rs @@ -1,7 +1,3 @@ -extern crate crossbeam_queue; -extern crate crossbeam_utils; -extern crate rand; - use std::sync::atomic::{AtomicUsize, Ordering}; use crossbeam_queue::SegQueue; diff --git a/crossbeam-skiplist/README.md b/crossbeam-skiplist/README.md index 288b9bc26..5c31ac411 100644 --- a/crossbeam-skiplist/README.md +++ b/crossbeam-skiplist/README.md @@ -25,12 +25,6 @@ Add this to your `Cargo.toml`: [dependencies] crossbeam-skiplist = "0.1" ``` - -Next, add this to your crate: - -```rust -extern crate crossbeam_skiplist; -``` --> ## Compatibility diff --git a/crossbeam-skiplist/benches/btree.rs b/crossbeam-skiplist/benches/btree.rs index 078392fd7..fa496da56 100644 --- a/crossbeam-skiplist/benches/btree.rs +++ b/crossbeam-skiplist/benches/btree.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate crossbeam_skiplist; extern crate test; use test::{black_box, Bencher}; diff --git a/crossbeam-skiplist/benches/hash.rs b/crossbeam-skiplist/benches/hash.rs index a472e627a..0cead2dd1 100644 --- a/crossbeam-skiplist/benches/hash.rs +++ b/crossbeam-skiplist/benches/hash.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate crossbeam_skiplist; extern crate test; use test::{black_box, Bencher}; diff --git a/crossbeam-skiplist/benches/skiplist.rs b/crossbeam-skiplist/benches/skiplist.rs index cb9b7f77d..9bcb3839f 100644 --- a/crossbeam-skiplist/benches/skiplist.rs +++ b/crossbeam-skiplist/benches/skiplist.rs @@ -1,11 +1,10 @@ #![feature(test)] -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_skiplist; extern crate test; use test::{black_box, Bencher}; +use crossbeam_epoch as epoch; use crossbeam_skiplist::SkipList; #[bench] diff --git a/crossbeam-skiplist/benches/skipmap.rs b/crossbeam-skiplist/benches/skipmap.rs index a02c17446..a7105c931 100644 --- a/crossbeam-skiplist/benches/skipmap.rs +++ b/crossbeam-skiplist/benches/skipmap.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate crossbeam_skiplist; extern crate test; use test::{black_box, Bencher}; diff --git a/crossbeam-skiplist/examples/simple.rs b/crossbeam-skiplist/examples/simple.rs index 31095b0b0..57320d434 100644 --- a/crossbeam-skiplist/examples/simple.rs +++ b/crossbeam-skiplist/examples/simple.rs @@ -1,5 +1,3 @@ -// extern crate crossbeam_skiplist; - // use std::time::Instant; fn main() { diff --git a/crossbeam-skiplist/src/base.rs b/crossbeam-skiplist/src/base.rs index 659112dfa..3ccb0932a 100644 --- a/crossbeam-skiplist/src/base.rs +++ b/crossbeam-skiplist/src/base.rs @@ -265,7 +265,7 @@ where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Node") .field(&self.key) .field(&self.value) @@ -277,7 +277,7 @@ where /// /// The result indicates whether the key was found, as well as what were the adjacent nodes to the /// key on each level of the skip list. -struct Position<'a, K: 'a, V: 'a> { +struct Position<'a, K, V> { /// Reference to a node with the given key, if found. /// /// If this is `Some` then it will point to the same node as `right[0]`. @@ -470,7 +470,7 @@ where } /// Finds an entry with the specified key, or inserts a new `key`-`value` pair if none exist. - pub fn get_or_insert(&self, key: K, value: V, guard: &Guard) -> RefEntry { + pub fn get_or_insert(&self, key: K, value: V, guard: &Guard) -> RefEntry<'_, K, V> { self.insert_internal(key, value, false, guard) } @@ -486,7 +486,7 @@ where } /// Returns an iterator over all entries in the skip list. - pub fn ref_iter(&self) -> RefIter { + pub fn ref_iter(&self) -> RefIter<'_, K, V> { RefIter { parent: self, head: None, @@ -831,7 +831,13 @@ where /// Inserts an entry with the specified `key` and `value`. /// /// If `replace` is `true`, then any existing entry with this key will first be removed. - fn insert_internal(&self, key: K, value: V, replace: bool, guard: &Guard) -> RefEntry { + fn insert_internal( + &self, + key: K, + value: V, + replace: bool, + guard: &Guard, + ) -> RefEntry<'_, K, V> { self.check_guard(guard); unsafe { @@ -1048,12 +1054,12 @@ where /// /// If there is an existing entry with this key, it will be removed before inserting the new /// one. - pub fn insert(&self, key: K, value: V, guard: &Guard) -> RefEntry { + pub fn insert(&self, key: K, value: V, guard: &Guard) -> RefEntry<'_, K, V> { self.insert_internal(key, value, true, guard) } /// Removes an entry with the specified `key` from the map and returns it. - pub fn remove(&self, key: &Q, guard: &Guard) -> Option> + pub fn remove(&self, key: &Q, guard: &Guard) -> Option> where K: Borrow, Q: Ord + ?Sized, @@ -1118,7 +1124,7 @@ where } /// Removes an entry from the front of the skip list. - pub fn pop_front(&self, guard: &Guard) -> Option> { + pub fn pop_front(&self, guard: &Guard) -> Option> { self.check_guard(guard); loop { let e = self.front(guard)?; @@ -1131,7 +1137,7 @@ where } /// Removes an entry from the back of the skip list. - pub fn pop_back(&self, guard: &Guard) -> Option> { + pub fn pop_back(&self, guard: &Guard) -> Option> { self.check_guard(guard); loop { let e = self.back(guard)?; @@ -1216,7 +1222,7 @@ where K: Ord + fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("SkipList { .. }") } } @@ -1252,7 +1258,7 @@ impl IntoIterator for SkipList { /// The lifetimes of the key and value are the same as that of the `Guard` /// used when creating the `Entry` (`'g`). This lifetime is also constrained to /// not outlive the `SkipList`. -pub struct Entry<'a: 'g, 'g, K: 'a, V: 'a> { +pub struct Entry<'a: 'g, 'g, K, V> { parent: &'a SkipList, node: &'g Node, guard: &'g Guard, @@ -1324,12 +1330,12 @@ impl<'a: 'g, 'g, K, V> Clone for Entry<'a, 'g, K, V> { } } -impl<'a, 'g, K, V> fmt::Debug for Entry<'a, 'g, K, V> +impl fmt::Debug for Entry<'_, '_, K, V> where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Entry") .field(self.key()) .field(self.value()) @@ -1394,7 +1400,7 @@ where /// /// You *must* call `release` to free this type, otherwise the node will be /// leaked. This is because releasing the entry requires a `Guard`. -pub struct RefEntry<'a, K: 'a, V: 'a> { +pub struct RefEntry<'a, K, V> { parent: &'a SkipList, node: &'a Node, } @@ -1455,7 +1461,7 @@ impl<'a, K: 'a, V: 'a> RefEntry<'a, K, V> { } } -impl<'a, K, V> RefEntry<'a, K, V> +impl RefEntry<'_, K, V> where K: Ord + Send + 'static, V: Send + 'static, @@ -1495,12 +1501,12 @@ impl<'a, K, V> Clone for RefEntry<'a, K, V> { } } -impl<'a, K, V> fmt::Debug for RefEntry<'a, K, V> +impl fmt::Debug for RefEntry<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("RefEntry") .field(self.key()) .field(self.value()) @@ -1567,7 +1573,7 @@ where } /// An iterator over the entries of a `SkipList`. -pub struct Iter<'a: 'g, 'g, K: 'a, V: 'a> { +pub struct Iter<'a: 'g, 'g, K, V> { parent: &'a SkipList, head: Option<&'g Node>, tail: Option<&'g Node>, @@ -1628,12 +1634,12 @@ where } } -impl<'a, 'g, K, V> fmt::Debug for Iter<'a, 'g, K, V> +impl fmt::Debug for Iter<'_, '_, K, V> where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Iter") .field("head", &self.head.map(|n| (&n.key, &n.value))) .field("tail", &self.tail.map(|n| (&n.key, &n.value))) @@ -1642,18 +1648,18 @@ where } /// An iterator over reference-counted entries of a `SkipList`. -pub struct RefIter<'a, K: 'a, V: 'a> { +pub struct RefIter<'a, K, V> { parent: &'a SkipList, head: Option>, tail: Option>, } -impl<'a, K, V> fmt::Debug for RefIter<'a, K, V> +impl fmt::Debug for RefIter<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut d = f.debug_struct("RefIter"); match &self.head { None => d.field("head", &None::<(&K, &V)>), @@ -1725,7 +1731,7 @@ where } /// An iterator over a subset of entries of a `SkipList`. -pub struct Range<'a: 'g, 'g, Q, R, K: 'a, V: 'a> +pub struct Range<'a: 'g, 'g, Q, R, K, V> where K: Ord + Borrow, R: RangeBounds, @@ -1807,14 +1813,14 @@ where } } -impl<'a, 'g, Q, R, K, V> fmt::Debug for Range<'a, 'g, Q, R, K, V> +impl fmt::Debug for Range<'_, '_, Q, R, K, V> where K: Ord + Borrow + fmt::Debug, V: fmt::Debug, R: RangeBounds + fmt::Debug, Q: Ord + ?Sized, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Range") .field("range", &self.range) .field("head", &self.head) @@ -1824,7 +1830,7 @@ where } /// An iterator over reference-counted subset of entries of a `SkipList`. -pub struct RefRange<'a, Q, R, K: 'a, V: 'a> +pub struct RefRange<'a, Q, R, K, V> where K: Ord + Borrow, R: RangeBounds, @@ -1837,7 +1843,7 @@ where _marker: PhantomData Q>, // covariant over `Q` } -unsafe impl<'a, Q, R, K, V> Send for RefRange<'a, Q, R, K, V> +unsafe impl Send for RefRange<'_, Q, R, K, V> where K: Ord + Borrow, R: RangeBounds, @@ -1845,7 +1851,7 @@ where { } -unsafe impl<'a, Q, R, K, V> Sync for RefRange<'a, Q, R, K, V> +unsafe impl Sync for RefRange<'_, Q, R, K, V> where K: Ord + Borrow, R: RangeBounds, @@ -1853,14 +1859,14 @@ where { } -impl<'a, Q, R, K, V> fmt::Debug for RefRange<'a, Q, R, K, V> +impl fmt::Debug for RefRange<'_, Q, R, K, V> where K: Ord + Borrow + fmt::Debug, V: fmt::Debug, R: RangeBounds + fmt::Debug, Q: Ord + ?Sized, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RefRange") .field("range", &self.range) .field("head", &self.head) @@ -1987,7 +1993,7 @@ impl Iterator for IntoIter { } impl fmt::Debug for IntoIter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("IntoIter { .. }") } } diff --git a/crossbeam-skiplist/src/lib.rs b/crossbeam-skiplist/src/lib.rs index 2d36325b0..566895fb9 100644 --- a/crossbeam-skiplist/src/lib.rs +++ b/crossbeam-skiplist/src/lib.rs @@ -1,23 +1,18 @@ //! TODO -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] -#[macro_use] -extern crate cfg_if; -#[cfg(feature = "alloc")] -extern crate alloc; -#[cfg(feature = "std")] -extern crate core; +use cfg_if::cfg_if; #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] cfg_if! { if #[cfg(feature = "alloc")] { - extern crate crossbeam_epoch as epoch; - extern crate crossbeam_utils as utils; - extern crate scopeguard; + extern crate alloc; + + use crossbeam_epoch as epoch; + use crossbeam_utils as utils; pub mod base; #[doc(inline)] diff --git a/crossbeam-skiplist/src/map.rs b/crossbeam-skiplist/src/map.rs index 81c6ff179..079150f32 100644 --- a/crossbeam-skiplist/src/map.rs +++ b/crossbeam-skiplist/src/map.rs @@ -42,13 +42,13 @@ where K: Ord, { /// Returns the entry with the smallest key. - pub fn front(&self) -> Option> { + pub fn front(&self) -> Option> { let guard = &epoch::pin(); try_pin_loop(|| self.inner.front(guard)).map(Entry::new) } /// Returns the entry with the largest key. - pub fn back(&self) -> Option> { + pub fn back(&self) -> Option> { let guard = &epoch::pin(); try_pin_loop(|| self.inner.back(guard)).map(Entry::new) } @@ -64,7 +64,7 @@ where } /// Returns an entry with the specified `key`. - pub fn get(&self, key: &Q) -> Option> + pub fn get(&self, key: &Q) -> Option> where K: Borrow, Q: Ord + ?Sized, @@ -98,13 +98,13 @@ where } /// Finds an entry with the specified key, or inserts a new `key`-`value` pair if none exist. - pub fn get_or_insert(&self, key: K, value: V) -> Entry { + pub fn get_or_insert(&self, key: K, value: V) -> Entry<'_, K, V> { let guard = &epoch::pin(); Entry::new(self.inner.get_or_insert(key, value, guard)) } /// Returns an iterator over all entries in the map. - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, K, V> { Iter { inner: self.inner.ref_iter(), } @@ -132,13 +132,13 @@ where /// /// If there is an existing entry with this key, it will be removed before inserting the new /// one. - pub fn insert(&self, key: K, value: V) -> Entry { + pub fn insert(&self, key: K, value: V) -> Entry<'_, K, V> { let guard = &epoch::pin(); Entry::new(self.inner.insert(key, value, guard)) } /// Removes an entry with the specified `key` from the map and returns it. - pub fn remove(&self, key: &Q) -> Option> + pub fn remove(&self, key: &Q) -> Option> where K: Borrow, Q: Ord + ?Sized, @@ -148,13 +148,13 @@ where } /// Removes an entry from the front of the map. - pub fn pop_front(&self) -> Option> { + pub fn pop_front(&self) -> Option> { let guard = &epoch::pin(); self.inner.pop_front(guard).map(Entry::new) } /// Removes an entry from the back of the map. - pub fn pop_back(&self) -> Option> { + pub fn pop_back(&self) -> Option> { let guard = &epoch::pin(); self.inner.pop_back(guard).map(Entry::new) } @@ -177,7 +177,7 @@ where K: Ord + fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("SkipMap { .. }") } } @@ -222,7 +222,7 @@ where } /// A reference-counted entry in a map. -pub struct Entry<'a, K: 'a, V: 'a> { +pub struct Entry<'a, K, V> { inner: ManuallyDrop>, } @@ -249,7 +249,7 @@ impl<'a, K, V> Entry<'a, K, V> { } } -impl<'a, K, V> Drop for Entry<'a, K, V> { +impl Drop for Entry<'_, K, V> { fn drop(&mut self) { unsafe { ManuallyDrop::into_inner(ptr::read(&mut self.inner)).release_with_pin(epoch::pin); @@ -286,7 +286,7 @@ where } } -impl<'a, K, V> Entry<'a, K, V> +impl Entry<'_, K, V> where K: Ord + Send + 'static, V: Send + 'static, @@ -308,12 +308,12 @@ impl<'a, K, V> Clone for Entry<'a, K, V> { } } -impl<'a, K, V> fmt::Debug for Entry<'a, K, V> +impl fmt::Debug for Entry<'_, K, V> where K: fmt::Debug, V: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Entry") .field(self.key()) .field(self.value()) @@ -335,13 +335,13 @@ impl Iterator for IntoIter { } impl fmt::Debug for IntoIter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("IntoIter { .. }") } } /// An iterator over the entries of a `SkipMap`. -pub struct Iter<'a, K: 'a, V: 'a> { +pub struct Iter<'a, K, V> { inner: base::RefIter<'a, K, V>, } @@ -367,14 +367,14 @@ where } } -impl<'a, K, V> fmt::Debug for Iter<'a, K, V> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Iter<'_, K, V> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Iter { .. }") } } /// An iterator over the entries of a `SkipMap`. -pub struct Range<'a, Q, R, K: 'a, V: 'a> +pub struct Range<'a, Q, R, K, V> where K: Ord + Borrow, R: RangeBounds, @@ -409,14 +409,14 @@ where } } -impl<'a, Q, R, K, V> fmt::Debug for Range<'a, Q, R, K, V> +impl fmt::Debug for Range<'_, Q, R, K, V> where K: Ord + Borrow + fmt::Debug, V: fmt::Debug, R: RangeBounds + fmt::Debug, Q: Ord + ?Sized, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Range") .field("range", &self.inner.range) .field("head", &self.inner.head) diff --git a/crossbeam-skiplist/src/set.rs b/crossbeam-skiplist/src/set.rs index 6610d8507..b007d2a88 100644 --- a/crossbeam-skiplist/src/set.rs +++ b/crossbeam-skiplist/src/set.rs @@ -39,12 +39,12 @@ where T: Ord, { /// Returns the entry with the smallest key. - pub fn front(&self) -> Option> { + pub fn front(&self) -> Option> { self.inner.front().map(Entry::new) } /// Returns the entry with the largest key. - pub fn back(&self) -> Option> { + pub fn back(&self) -> Option> { self.inner.back().map(Entry::new) } @@ -58,7 +58,7 @@ where } /// Returns an entry with the specified `key`. - pub fn get(&self, key: &Q) -> Option> + pub fn get(&self, key: &Q) -> Option> where T: Borrow, Q: Ord + ?Sized, @@ -89,12 +89,12 @@ where } /// Finds an entry with the specified key, or inserts a new `key`-`value` pair if none exist. - pub fn get_or_insert(&self, key: T) -> Entry { + pub fn get_or_insert(&self, key: T) -> Entry<'_, T> { Entry::new(self.inner.get_or_insert(key, ())) } /// Returns an iterator over all entries in the map. - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, T> { Iter { inner: self.inner.iter(), } @@ -121,12 +121,12 @@ where /// /// If there is an existing entry with this key, it will be removed before inserting the new /// one. - pub fn insert(&self, key: T) -> Entry { + pub fn insert(&self, key: T) -> Entry<'_, T> { Entry::new(self.inner.insert(key, ())) } /// Removes an entry with the specified key from the set and returns it. - pub fn remove(&self, key: &Q) -> Option> + pub fn remove(&self, key: &Q) -> Option> where T: Borrow, Q: Ord + ?Sized, @@ -135,12 +135,12 @@ where } /// Removes an entry from the front of the map. - pub fn pop_front(&self) -> Option> { + pub fn pop_front(&self) -> Option> { self.inner.pop_front().map(Entry::new) } /// Removes an entry from the back of the map. - pub fn pop_back(&self) -> Option> { + pub fn pop_back(&self) -> Option> { self.inner.pop_back().map(Entry::new) } @@ -160,7 +160,7 @@ impl fmt::Debug for SkipSet where T: Ord + fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("SkipSet { .. }") } } @@ -205,7 +205,7 @@ where } /// TODO -pub struct Entry<'a, T: 'a> { +pub struct Entry<'a, T> { inner: map::Entry<'a, T, ()>, } @@ -250,7 +250,7 @@ where } } -impl<'a, T> Entry<'a, T> +impl Entry<'_, T> where T: Ord + Send + 'static, { @@ -270,11 +270,11 @@ impl<'a, T> Clone for Entry<'a, T> { } } -impl<'a, T> fmt::Debug for Entry<'a, T> +impl fmt::Debug for Entry<'_, T> where T: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Entry") .field("value", self.value()) .finish() @@ -295,13 +295,13 @@ impl Iterator for IntoIter { } impl fmt::Debug for IntoIter { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("IntoIter { .. }") } } /// An iterator over the entries of a `SkipSet`. -pub struct Iter<'a, T: 'a> { +pub struct Iter<'a, T> { inner: map::Iter<'a, T, ()>, } @@ -325,14 +325,14 @@ where } } -impl<'a, T> fmt::Debug for Iter<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Iter<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Iter { .. }") } } /// An iterator over the entries of a `SkipMap`. -pub struct Range<'a, Q, R, T: 'a> +pub struct Range<'a, Q, R, T> where T: Ord + Borrow, R: RangeBounds, @@ -365,13 +365,13 @@ where } } -impl<'a, Q, R, T> fmt::Debug for Range<'a, Q, R, T> +impl fmt::Debug for Range<'_, Q, R, T> where T: Ord + Borrow + fmt::Debug, R: RangeBounds + fmt::Debug, Q: Ord + ?Sized, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Range") .field("range", &self.inner.inner.range) .field("head", &self.inner.inner.head.as_ref().map(|e| e.key())) diff --git a/crossbeam-skiplist/tests/base.rs b/crossbeam-skiplist/tests/base.rs index f3aee7d0d..7f43fa754 100644 --- a/crossbeam-skiplist/tests/base.rs +++ b/crossbeam-skiplist/tests/base.rs @@ -1,10 +1,8 @@ -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_skiplist as skiplist; - use std::ops::Bound; use std::sync::atomic::{AtomicUsize, Ordering}; -use crate::skiplist::SkipList; +use crossbeam_epoch as epoch; +use crossbeam_skiplist::SkipList; #[test] fn new() { diff --git a/crossbeam-skiplist/tests/map.rs b/crossbeam-skiplist/tests/map.rs index ae2d57212..3d48f145b 100644 --- a/crossbeam-skiplist/tests/map.rs +++ b/crossbeam-skiplist/tests/map.rs @@ -1,6 +1,4 @@ -extern crate crossbeam_skiplist as skiplist; - -use crate::skiplist::SkipMap; +use crossbeam_skiplist::SkipMap; #[test] fn smoke() { diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs index 0faeb80c8..f905fea19 100644 --- a/crossbeam-skiplist/tests/set.rs +++ b/crossbeam-skiplist/tests/set.rs @@ -1,6 +1,4 @@ -extern crate crossbeam_skiplist as skiplist; - -use crate::skiplist::SkipSet; +use crossbeam_skiplist::SkipSet; #[test] fn smoke() { diff --git a/crossbeam-utils/README.md b/crossbeam-utils/README.md index 39b82c862..272262ff1 100644 --- a/crossbeam-utils/README.md +++ b/crossbeam-utils/README.md @@ -51,12 +51,6 @@ Add this to your `Cargo.toml`: crossbeam-utils = "0.7" ``` -Next, add this to your crate: - -```rust -extern crate crossbeam_utils; -``` - ## Compatibility Crossbeam Utils supports stable Rust releases going back at least six months, diff --git a/crossbeam-utils/benches/atomic_cell.rs b/crossbeam-utils/benches/atomic_cell.rs index 8587dba1d..938a8fe38 100644 --- a/crossbeam-utils/benches/atomic_cell.rs +++ b/crossbeam-utils/benches/atomic_cell.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate crossbeam_utils; extern crate test; use std::sync::Barrier; diff --git a/crossbeam-utils/build.rs b/crossbeam-utils/build.rs index 6bd8d3109..86c40ab9b 100644 --- a/crossbeam-utils/build.rs +++ b/crossbeam-utils/build.rs @@ -1,5 +1,3 @@ -extern crate autocfg; - fn main() { let cfg = autocfg::new(); cfg.emit_type_cfg("core::sync::atomic::AtomicU8", "has_atomic_u8"); diff --git a/crossbeam-utils/src/atomic/atomic_cell.rs b/crossbeam-utils/src/atomic/atomic_cell.rs index c687af310..399d902a3 100644 --- a/crossbeam-utils/src/atomic/atomic_cell.rs +++ b/crossbeam-utils/src/atomic/atomic_cell.rs @@ -590,7 +590,7 @@ impl Default for AtomicCell { } impl fmt::Debug for AtomicCell { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("AtomicCell") .field("value", &self.load()) .finish() diff --git a/crossbeam-utils/src/atomic/mod.rs b/crossbeam-utils/src/atomic/mod.rs index 074b0ca53..7309c166d 100644 --- a/crossbeam-utils/src/atomic/mod.rs +++ b/crossbeam-utils/src/atomic/mod.rs @@ -1,5 +1,7 @@ //! Atomic types. +use cfg_if::cfg_if; + cfg_if! { // Use "wide" sequence lock if the pointer width <= 32 for preventing its counter against wrap // around. diff --git a/crossbeam-utils/src/backoff.rs b/crossbeam-utils/src/backoff.rs index c82c4b31f..adeea7c3a 100644 --- a/crossbeam-utils/src/backoff.rs +++ b/crossbeam-utils/src/backoff.rs @@ -270,7 +270,7 @@ impl Backoff { } impl fmt::Debug for Backoff { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Backoff") .field("step", &self.step) .field("is_completed", &self.is_completed()) diff --git a/crossbeam-utils/src/cache_padded.rs b/crossbeam-utils/src/cache_padded.rs index eff6303ba..612aa1966 100644 --- a/crossbeam-utils/src/cache_padded.rs +++ b/crossbeam-utils/src/cache_padded.rs @@ -125,7 +125,7 @@ impl DerefMut for CachePadded { } impl fmt::Debug for CachePadded { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("CachePadded") .field("value", &self.value) .finish() diff --git a/crossbeam-utils/src/lib.rs b/crossbeam-utils/src/lib.rs index 44602fb34..e76934b99 100644 --- a/crossbeam-utils/src/lib.rs +++ b/crossbeam-utils/src/lib.rs @@ -26,16 +26,10 @@ //! [`CachePadded`]: struct.CachePadded.html //! [`scope`]: thread/fn.scope.html -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] -#[macro_use] -extern crate cfg_if; -#[cfg(feature = "std")] -extern crate core; - #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] pub mod atomic; @@ -45,11 +39,10 @@ pub use crate::cache_padded::CachePadded; mod backoff; pub use crate::backoff::Backoff; +use cfg_if::cfg_if; + cfg_if! { if #[cfg(feature = "std")] { - #[macro_use] - extern crate lazy_static; - pub mod sync; pub mod thread; } diff --git a/crossbeam-utils/src/sync/parker.rs b/crossbeam-utils/src/sync/parker.rs index af710cf7f..44efbb09b 100644 --- a/crossbeam-utils/src/sync/parker.rs +++ b/crossbeam-utils/src/sync/parker.rs @@ -191,7 +191,7 @@ impl Parker { } impl fmt::Debug for Parker { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Parker { .. }") } } @@ -280,7 +280,7 @@ impl Unparker { } impl fmt::Debug for Unparker { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Unparker { .. }") } } diff --git a/crossbeam-utils/src/sync/sharded_lock.rs b/crossbeam-utils/src/sync/sharded_lock.rs index 168700a64..b6581a483 100644 --- a/crossbeam-utils/src/sync/sharded_lock.rs +++ b/crossbeam-utils/src/sync/sharded_lock.rs @@ -10,6 +10,7 @@ use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::thread::{self, ThreadId}; use crate::CachePadded; +use lazy_static::lazy_static; /// The number of shards per sharded lock. Must be a power of two. const NUM_SHARDS: usize = 8; @@ -215,7 +216,7 @@ impl ShardedLock { /// Err(_) => unreachable!(), /// }; /// ``` - pub fn try_read(&self) -> TryLockResult> { + pub fn try_read(&self) -> TryLockResult> { // Take the current thread index and map it to a shard index. Thread indices will tend to // distribute shards among threads equally, thus reducing contention due to read-locking. let current_index = current_index().unwrap_or(0); @@ -266,7 +267,7 @@ impl ShardedLock { /// assert!(r.is_ok()); /// }).join().unwrap(); /// ``` - pub fn read(&self) -> LockResult> { + pub fn read(&self) -> LockResult> { // Take the current thread index and map it to a shard index. Thread indices will tend to // distribute shards among threads equally, thus reducing contention due to read-locking. let current_index = current_index().unwrap_or(0); @@ -308,7 +309,7 @@ impl ShardedLock { /// /// assert!(lock.try_write().is_err()); /// ``` - pub fn try_write(&self) -> TryLockResult> { + pub fn try_write(&self) -> TryLockResult> { let mut poisoned = false; let mut blocked = None; @@ -379,7 +380,7 @@ impl ShardedLock { /// /// assert!(lock.try_read().is_err()); /// ``` - pub fn write(&self) -> LockResult> { + pub fn write(&self) -> LockResult> { let mut poisoned = false; // Write-lock each shard in succession. @@ -416,7 +417,7 @@ impl ShardedLock { } impl fmt::Debug for ShardedLock { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.try_read() { Ok(guard) => f .debug_struct("ShardedLock") @@ -429,7 +430,7 @@ impl fmt::Debug for ShardedLock { Err(TryLockError::WouldBlock) => { struct LockedPlaceholder; impl fmt::Debug for LockedPlaceholder { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("") } } @@ -456,15 +457,15 @@ impl From for ShardedLock { /// A guard used to release the shared read access of a [`ShardedLock`] when dropped. /// /// [`ShardedLock`]: struct.ShardedLock.html -pub struct ShardedLockReadGuard<'a, T: ?Sized + 'a> { +pub struct ShardedLockReadGuard<'a, T: ?Sized> { lock: &'a ShardedLock, _guard: RwLockReadGuard<'a, ()>, _marker: PhantomData>, } -unsafe impl<'a, T: ?Sized + Sync> Sync for ShardedLockReadGuard<'a, T> {} +unsafe impl Sync for ShardedLockReadGuard<'_, T> {} -impl<'a, T: ?Sized> Deref for ShardedLockReadGuard<'a, T> { +impl Deref for ShardedLockReadGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -472,16 +473,16 @@ impl<'a, T: ?Sized> Deref for ShardedLockReadGuard<'a, T> { } } -impl<'a, T: fmt::Debug> fmt::Debug for ShardedLockReadGuard<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for ShardedLockReadGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ShardedLockReadGuard") .field("lock", &self.lock) .finish() } } -impl<'a, T: ?Sized + fmt::Display> fmt::Display for ShardedLockReadGuard<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Display for ShardedLockReadGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } @@ -489,14 +490,14 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for ShardedLockReadGuard<'a, T> /// A guard used to release the exclusive write access of a [`ShardedLock`] when dropped. /// /// [`ShardedLock`]: struct.ShardedLock.html -pub struct ShardedLockWriteGuard<'a, T: ?Sized + 'a> { +pub struct ShardedLockWriteGuard<'a, T: ?Sized> { lock: &'a ShardedLock, _marker: PhantomData>, } -unsafe impl<'a, T: ?Sized + Sync> Sync for ShardedLockWriteGuard<'a, T> {} +unsafe impl Sync for ShardedLockWriteGuard<'_, T> {} -impl<'a, T: ?Sized> Drop for ShardedLockWriteGuard<'a, T> { +impl Drop for ShardedLockWriteGuard<'_, T> { fn drop(&mut self) { // Unlock the shards in reverse order of locking. for shard in self.lock.shards.iter().rev() { @@ -509,21 +510,21 @@ impl<'a, T: ?Sized> Drop for ShardedLockWriteGuard<'a, T> { } } -impl<'a, T: fmt::Debug> fmt::Debug for ShardedLockWriteGuard<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for ShardedLockWriteGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ShardedLockWriteGuard") .field("lock", &self.lock) .finish() } } -impl<'a, T: ?Sized + fmt::Display> fmt::Display for ShardedLockWriteGuard<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Display for ShardedLockWriteGuard<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } -impl<'a, T: ?Sized> Deref for ShardedLockWriteGuard<'a, T> { +impl Deref for ShardedLockWriteGuard<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -531,7 +532,7 @@ impl<'a, T: ?Sized> Deref for ShardedLockWriteGuard<'a, T> { } } -impl<'a, T: ?Sized> DerefMut for ShardedLockWriteGuard<'a, T> { +impl DerefMut for ShardedLockWriteGuard<'_, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.lock.value.get() } } diff --git a/crossbeam-utils/src/sync/wait_group.rs b/crossbeam-utils/src/sync/wait_group.rs index 0527b3159..7341fdba0 100644 --- a/crossbeam-utils/src/sync/wait_group.rs +++ b/crossbeam-utils/src/sync/wait_group.rs @@ -130,7 +130,7 @@ impl Clone for WaitGroup { } impl fmt::Debug for WaitGroup { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let count: &usize = &*self.inner.count.lock().unwrap(); f.debug_struct("WaitGroup").field("count", count).finish() } diff --git a/crossbeam-utils/src/thread.rs b/crossbeam-utils/src/thread.rs index f546452e8..ab51322a5 100644 --- a/crossbeam-utils/src/thread.rs +++ b/crossbeam-utils/src/thread.rs @@ -122,6 +122,7 @@ use std::sync::{Arc, Mutex}; use std::thread; use crate::sync::WaitGroup; +use cfg_if::cfg_if; type SharedVec = Arc>>; type SharedOption = Arc>>; @@ -205,7 +206,7 @@ pub struct Scope<'env> { _marker: PhantomData<&'env mut &'env ()>, } -unsafe impl<'env> Sync for Scope<'env> {} +unsafe impl Sync for Scope<'_> {} impl<'env> Scope<'env> { /// Spawns a scoped thread. @@ -268,8 +269,8 @@ impl<'env> Scope<'env> { } } -impl<'env> fmt::Debug for Scope<'env> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for Scope<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Scope { .. }") } } @@ -308,7 +309,7 @@ impl<'env> fmt::Debug for Scope<'env> { /// [naming-threads]: https://doc.rust-lang.org/std/thread/index.html#naming-threads /// [stack-size]: https://doc.rust-lang.org/std/thread/index.html#stack-size #[derive(Debug)] -pub struct ScopedThreadBuilder<'scope, 'env: 'scope> { +pub struct ScopedThreadBuilder<'scope, 'env> { scope: &'scope Scope<'env>, builder: thread::Builder, } @@ -448,8 +449,8 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { } } -unsafe impl<'scope, T> Send for ScopedJoinHandle<'scope, T> {} -unsafe impl<'scope, T> Sync for ScopedJoinHandle<'scope, T> {} +unsafe impl Send for ScopedJoinHandle<'_, T> {} +unsafe impl Sync for ScopedJoinHandle<'_, T> {} /// A handle that can be used to join its scoped thread. pub struct ScopedJoinHandle<'scope, T> { @@ -466,7 +467,7 @@ pub struct ScopedJoinHandle<'scope, T> { _marker: PhantomData<&'scope ()>, } -impl<'scope, T> ScopedJoinHandle<'scope, T> { +impl ScopedJoinHandle<'_, T> { /// Waits for the thread to finish and returns its result. /// /// If the child thread panics, an error is returned. @@ -526,7 +527,7 @@ cfg_if! { if #[cfg(unix)] { use std::os::unix::thread::{JoinHandleExt, RawPthread}; - impl<'scope, T> JoinHandleExt for ScopedJoinHandle<'scope, T> { + impl JoinHandleExt for ScopedJoinHandle<'_, T> { fn as_pthread_t(&self) -> RawPthread { // Borrow the handle. The handle will surely be available because the root scope waits // for nested scopes before joining remaining threads. @@ -540,7 +541,7 @@ cfg_if! { } else if #[cfg(windows)] { use std::os::windows::io::{AsRawHandle, IntoRawHandle, RawHandle}; - impl<'scope, T> AsRawHandle for ScopedJoinHandle<'scope, T> { + impl AsRawHandle for ScopedJoinHandle<'_, T> { fn as_raw_handle(&self) -> RawHandle { // Borrow the handle. The handle will surely be available because the root scope waits // for nested scopes before joining remaining threads. @@ -550,7 +551,7 @@ cfg_if! { } #[cfg(windows)] - impl<'scope, T> IntoRawHandle for ScopedJoinHandle<'scope, T> { + impl IntoRawHandle for ScopedJoinHandle<'_, T> { fn into_raw_handle(self) -> RawHandle { self.as_raw_handle() } @@ -558,8 +559,8 @@ cfg_if! { } } -impl<'scope, T> fmt::Debug for ScopedJoinHandle<'scope, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl fmt::Debug for ScopedJoinHandle<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("ScopedJoinHandle { .. }") } } diff --git a/crossbeam-utils/tests/atomic_cell.rs b/crossbeam-utils/tests/atomic_cell.rs index f2cc0dae2..0fc733c16 100644 --- a/crossbeam-utils/tests/atomic_cell.rs +++ b/crossbeam-utils/tests/atomic_cell.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_utils; - use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; diff --git a/crossbeam-utils/tests/cache_padded.rs b/crossbeam-utils/tests/cache_padded.rs index 8ad7d40a4..be90cbe91 100644 --- a/crossbeam-utils/tests/cache_padded.rs +++ b/crossbeam-utils/tests/cache_padded.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_utils; - use std::cell::Cell; use std::mem; diff --git a/crossbeam-utils/tests/parker.rs b/crossbeam-utils/tests/parker.rs index 3f4514626..f657eb1cf 100644 --- a/crossbeam-utils/tests/parker.rs +++ b/crossbeam-utils/tests/parker.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_utils; - use std::thread::sleep; use std::time::Duration; use std::u32; diff --git a/crossbeam-utils/tests/sharded_lock.rs b/crossbeam-utils/tests/sharded_lock.rs index c98de7999..73bd489d3 100644 --- a/crossbeam-utils/tests/sharded_lock.rs +++ b/crossbeam-utils/tests/sharded_lock.rs @@ -1,6 +1,3 @@ -extern crate crossbeam_utils; -extern crate rand; - use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::channel; use std::sync::{Arc, TryLockError}; diff --git a/crossbeam-utils/tests/thread.rs b/crossbeam-utils/tests/thread.rs index 2116c7d0b..f3612571b 100644 --- a/crossbeam-utils/tests/thread.rs +++ b/crossbeam-utils/tests/thread.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_utils; - use std::any::Any; use std::sync::atomic::{AtomicUsize, Ordering}; use std::thread::sleep; diff --git a/crossbeam-utils/tests/wait_group.rs b/crossbeam-utils/tests/wait_group.rs index 1aa91997a..b6c2a2437 100644 --- a/crossbeam-utils/tests/wait_group.rs +++ b/crossbeam-utils/tests/wait_group.rs @@ -1,5 +1,3 @@ -extern crate crossbeam_utils; - use std::sync::mpsc; use std::thread; use std::time::Duration; diff --git a/src/lib.rs b/src/lib.rs index ef51f60e3..a637d601d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,20 +42,10 @@ //! [`CachePadded`]: utils/struct.CachePadded.html //! [`scope`]: fn.scope.html -#![warn(missing_docs)] -#![warn(missing_debug_implementations)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] -#[macro_use] -extern crate cfg_if; -#[cfg(feature = "alloc")] -extern crate alloc; -#[cfg(feature = "std")] -extern crate core; - -extern crate crossbeam_utils; - #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] pub use crossbeam_utils::atomic; @@ -65,16 +55,18 @@ pub mod utils { pub use crossbeam_utils::CachePadded; } +use cfg_if::cfg_if; + cfg_if! { if #[cfg(feature = "alloc")] { mod _epoch { - pub extern crate crossbeam_epoch; + pub use crossbeam_epoch; } #[doc(inline)] - pub use _epoch::crossbeam_epoch as epoch; + pub use crate::_epoch::crossbeam_epoch as epoch; mod _queue { - pub extern crate crossbeam_queue; + pub use crossbeam_queue; } #[doc(inline)] pub use crate::_queue::crossbeam_queue as queue; @@ -84,21 +76,18 @@ cfg_if! { cfg_if! { if #[cfg(feature = "std")] { mod _deque { - pub extern crate crossbeam_deque; + pub use crossbeam_deque; } #[doc(inline)] pub use crate::_deque::crossbeam_deque as deque; mod _channel { - pub extern crate crossbeam_channel; - pub use self::crossbeam_channel::*; + pub use crossbeam_channel; } #[doc(inline)] pub use crate::_channel::crossbeam_channel as channel; - // HACK(stjepang): This is the only way to reexport `select!` in Rust older than 1.30.0 - #[doc(hidden)] - pub use crate::_channel::*; + pub use crossbeam_channel::select; pub use crossbeam_utils::sync; pub use crossbeam_utils::thread; diff --git a/tests/subcrates.rs b/tests/subcrates.rs index b9a3b0d7b..21b99fb0e 100644 --- a/tests/subcrates.rs +++ b/tests/subcrates.rs @@ -1,7 +1,6 @@ //! Makes sure subcrates are properly re-exported. -#[macro_use] -extern crate crossbeam; +use crossbeam::select; #[test] fn channel() {