diff --git a/Cargo.toml b/Cargo.toml index 2ce52a7e1..b17e0fb90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam" # - Create "crossbeam-X.Y.Z" git tag version = "0.7.3" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -44,7 +45,7 @@ alloc = ["crossbeam-epoch/alloc", "crossbeam-queue/alloc"] nightly = ["crossbeam-epoch/nightly", "crossbeam-utils/nightly", "crossbeam-queue/nightly"] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" [dependencies.crossbeam-channel] version = "0.4" 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/Cargo.toml b/crossbeam-channel/Cargo.toml index f18dbf001..eeb6c563d 100644 --- a/crossbeam-channel/Cargo.toml +++ b/crossbeam-channel/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-channel" # - Create "crossbeam-channel-X.Y.Z" git tag version = "0.4.2" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0 AND BSD-2-Clause" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -23,7 +24,7 @@ default = ["std"] std = ["crossbeam-utils/std"] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" [dependencies.crossbeam-utils] version = "0.7" 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/benches/crossbeam.rs b/crossbeam-channel/benches/crossbeam.rs index 4dd956b12..9870c98bb 100644 --- a/crossbeam-channel/benches/crossbeam.rs +++ b/crossbeam-channel/benches/crossbeam.rs @@ -1,8 +1,5 @@ #![feature(test)] -extern crate crossbeam_channel; -extern crate crossbeam_utils; -extern crate num_cpus; extern crate test; use crossbeam_channel::{bounded, unbounded}; diff --git a/crossbeam-channel/benchmarks/Cargo.toml b/crossbeam-channel/benchmarks/Cargo.toml index 950bfe492..87cfead52 100644 --- a/crossbeam-channel/benchmarks/Cargo.toml +++ b/crossbeam-channel/benchmarks/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "benchmarks" version = "0.1.0" +edition = "2018" publish = false [dependencies] diff --git a/crossbeam-channel/benchmarks/atomicring.rs b/crossbeam-channel/benchmarks/atomicring.rs index 5db55009e..78cd6fcc8 100644 --- a/crossbeam-channel/benchmarks/atomicring.rs +++ b/crossbeam-channel/benchmarks/atomicring.rs @@ -1,6 +1,3 @@ -extern crate atomicring; -extern crate crossbeam; - use atomicring::AtomicRingBuffer; use std::thread; diff --git a/crossbeam-channel/benchmarks/atomicringqueue.rs b/crossbeam-channel/benchmarks/atomicringqueue.rs index 06b984e35..f0b97727a 100644 --- a/crossbeam-channel/benchmarks/atomicringqueue.rs +++ b/crossbeam-channel/benchmarks/atomicringqueue.rs @@ -1,6 +1,3 @@ -extern crate atomicring; -extern crate crossbeam; - use atomicring::AtomicRingQueue; use std::thread; diff --git a/crossbeam-channel/benchmarks/bus.rs b/crossbeam-channel/benchmarks/bus.rs index ac738126e..754f32db8 100644 --- a/crossbeam-channel/benchmarks/bus.rs +++ b/crossbeam-channel/benchmarks/bus.rs @@ -1,6 +1,3 @@ -extern crate bus; -extern crate crossbeam; - use bus::Bus; mod message; diff --git a/crossbeam-channel/benchmarks/chan.rs b/crossbeam-channel/benchmarks/chan.rs index b034b395d..17f4d9932 100644 --- a/crossbeam-channel/benchmarks/chan.rs +++ b/crossbeam-channel/benchmarks/chan.rs @@ -1,6 +1,4 @@ -#[macro_use] -extern crate chan; -extern crate crossbeam; +use chan::chan_select; mod message; @@ -9,7 +7,7 @@ const THREADS: usize = 4; fn new(cap: Option) -> (chan::Sender, chan::Receiver) { match cap { - None => chan::async(), + None => chan::r#async(), Some(cap) => chan::sync(cap), } } 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 2bd902557..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 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 bc7908f0f..030643279 100644 --- a/crossbeam-channel/src/channel.rs +++ b/crossbeam-channel/src/channel.rs @@ -7,11 +7,13 @@ use std::panic::{RefUnwindSafe, UnwindSafe}; use std::sync::Arc; use std::time::{Duration, Instant}; -use context::Context; -use counter; -use err::{RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError}; -use flavors; -use select::{Operation, SelectHandle, Token}; +use crate::context::Context; +use crate::counter; +use crate::err::{ + RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError, +}; +use crate::flavors; +use crate::select::{Operation, SelectHandle, Token}; /// Creates a channel of unbounded capacity. /// @@ -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/context.rs b/crossbeam-channel/src/context.rs index c6e5c15db..e2e8480f0 100644 --- a/crossbeam-channel/src/context.rs +++ b/crossbeam-channel/src/context.rs @@ -8,7 +8,7 @@ use std::time::Instant; use crossbeam_utils::Backoff; -use select::Selected; +use crate::select::Selected; /// Thread-local context used in select. #[derive(Debug, Clone)] 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/after.rs b/crossbeam-channel/src/flavors/after.rs index b57f8a787..3dff5aaad 100644 --- a/crossbeam-channel/src/flavors/after.rs +++ b/crossbeam-channel/src/flavors/after.rs @@ -6,10 +6,10 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; use std::time::{Duration, Instant}; -use context::Context; -use err::{RecvTimeoutError, TryRecvError}; -use select::{Operation, SelectHandle, Token}; -use utils; +use crate::context::Context; +use crate::err::{RecvTimeoutError, TryRecvError}; +use crate::select::{Operation, SelectHandle, Token}; +use crate::utils; /// Result of a receive operation. pub type AfterToken = Option; diff --git a/crossbeam-channel/src/flavors/array.rs b/crossbeam-channel/src/flavors/array.rs index 8d9bf7f9b..d7a6c26cc 100644 --- a/crossbeam-channel/src/flavors/array.rs +++ b/crossbeam-channel/src/flavors/array.rs @@ -22,10 +22,10 @@ use std::time::Instant; use crossbeam_utils::{Backoff, CachePadded}; -use context::Context; -use err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; -use select::{Operation, SelectHandle, Selected, Token}; -use waker::SyncWaker; +use crate::context::Context; +use crate::err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; +use crate::select::{Operation, SelectHandle, Selected, Token}; +use crate::waker::SyncWaker; /// A slot in a channel. struct Slot { @@ -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 a4ecbe753..532e8b6ad 100644 --- a/crossbeam-channel/src/flavors/list.rs +++ b/crossbeam-channel/src/flavors/list.rs @@ -9,10 +9,10 @@ use std::time::Instant; use crossbeam_utils::{Backoff, CachePadded}; -use context::Context; -use err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; -use select::{Operation, SelectHandle, Selected, Token}; -use waker::SyncWaker; +use crate::context::Context; +use crate::err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; +use crate::select::{Operation, SelectHandle, Selected, Token}; +use crate::waker::SyncWaker; // TODO(stjepang): Once we bump the minimum required Rust version to 1.28 or newer, re-apply the // following changes by @kleimkuhler: @@ -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/never.rs b/crossbeam-channel/src/flavors/never.rs index 5fb12e67e..e49d2147c 100644 --- a/crossbeam-channel/src/flavors/never.rs +++ b/crossbeam-channel/src/flavors/never.rs @@ -5,10 +5,10 @@ use std::marker::PhantomData; use std::time::Instant; -use context::Context; -use err::{RecvTimeoutError, TryRecvError}; -use select::{Operation, SelectHandle, Token}; -use utils; +use crate::context::Context; +use crate::err::{RecvTimeoutError, TryRecvError}; +use crate::select::{Operation, SelectHandle, Token}; +use crate::utils; /// This flavor doesn't need a token. pub type NeverToken = (); diff --git a/crossbeam-channel/src/flavors/tick.rs b/crossbeam-channel/src/flavors/tick.rs index 294111761..e8e7020ca 100644 --- a/crossbeam-channel/src/flavors/tick.rs +++ b/crossbeam-channel/src/flavors/tick.rs @@ -7,9 +7,9 @@ use std::time::{Duration, Instant}; use crossbeam_utils::atomic::AtomicCell; -use context::Context; -use err::{RecvTimeoutError, TryRecvError}; -use select::{Operation, SelectHandle, Token}; +use crate::context::Context; +use crate::err::{RecvTimeoutError, TryRecvError}; +use crate::select::{Operation, SelectHandle, Token}; /// Result of a receive operation. pub type TickToken = Option; diff --git a/crossbeam-channel/src/flavors/zero.rs b/crossbeam-channel/src/flavors/zero.rs index ee1bfc534..be647b55c 100644 --- a/crossbeam-channel/src/flavors/zero.rs +++ b/crossbeam-channel/src/flavors/zero.rs @@ -9,11 +9,11 @@ use std::time::Instant; use crossbeam_utils::Backoff; -use context::Context; -use err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; -use select::{Operation, SelectHandle, Selected, Token}; -use utils::Spinlock; -use waker::Waker; +use crate::context::Context; +use crate::err::{RecvTimeoutError, SendTimeoutError, TryRecvError, TrySendError}; +use crate::select::{Operation, SelectHandle, Selected, Token}; +use crate::utils::Spinlock; +use crate::waker::Waker; /// A pointer to a packet. pub type ZeroToken = usize; @@ -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 2d51df3dc..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; @@ -368,19 +358,19 @@ cfg_if! { /// Crate internals used by the `select!` macro. #[doc(hidden)] pub mod internal { - pub use select::SelectHandle; - pub use select::{select, select_timeout, try_select}; + pub use crate::select::SelectHandle; + pub use crate::select::{select, select_timeout, try_select}; } - pub use channel::{after, never, tick}; - pub use channel::{bounded, unbounded}; - pub use channel::{IntoIter, Iter, TryIter}; - pub use channel::{Receiver, Sender}; + pub use crate::channel::{after, never, tick}; + pub use crate::channel::{bounded, unbounded}; + pub use crate::channel::{IntoIter, Iter, TryIter}; + pub use crate::channel::{Receiver, Sender}; - pub use select::{Select, SelectedOperation}; + pub use crate::select::{Select, SelectedOperation}; - pub use err::{ReadyTimeoutError, SelectTimeoutError, TryReadyError, TrySelectError}; - pub use err::{RecvError, RecvTimeoutError, TryRecvError}; - pub use err::{SendError, SendTimeoutError, TrySendError}; + pub use crate::err::{ReadyTimeoutError, SelectTimeoutError, TryReadyError, TrySelectError}; + pub use crate::err::{RecvError, RecvTimeoutError, TryRecvError}; + pub use crate::err::{SendError, SendTimeoutError, TrySendError}; } } diff --git a/crossbeam-channel/src/select.rs b/crossbeam-channel/src/select.rs index 60c6a45dc..b3851b770 100644 --- a/crossbeam-channel/src/select.rs +++ b/crossbeam-channel/src/select.rs @@ -7,13 +7,13 @@ use std::time::{Duration, Instant}; use crossbeam_utils::Backoff; -use channel::{self, Receiver, Sender}; -use context::Context; -use err::{ReadyTimeoutError, TryReadyError}; -use err::{RecvError, SendError}; -use err::{SelectTimeoutError, TrySelectError}; -use flavors; -use utils; +use crate::channel::{self, Receiver, Sender}; +use crate::context::Context; +use crate::err::{ReadyTimeoutError, TryReadyError}; +use crate::err::{RecvError, SendError}; +use crate::err::{SelectTimeoutError, TrySelectError}; +use crate::flavors; +use crate::utils; /// Temporary data that gets initialized during select or a blocking operation, and is consumed by /// `read` or `write`. @@ -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/src/waker.rs b/crossbeam-channel/src/waker.rs index ceb7510f8..3d0af2616 100644 --- a/crossbeam-channel/src/waker.rs +++ b/crossbeam-channel/src/waker.rs @@ -3,9 +3,9 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::thread::{self, ThreadId}; -use context::Context; -use select::{Operation, Selected}; -use utils::Spinlock; +use crate::context::Context; +use crate::select::{Operation, Selected}; +use crate::utils::Spinlock; /// Represents a thread blocked on a specific channel operation. pub struct Entry { 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 bc7a95626..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) @@ -435,13 +432,13 @@ mod nonblock { } go!(c32, sync, i32receiver(c32, sync)); - let mut try = 0; + let mut r#try = 0; loop { select! { send(c32.tx(), 123) -> _ => break, default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("i32receiver buffer={}", buffer); panic!("fail") } @@ -454,7 +451,7 @@ mod nonblock { if buffer > 0 { sync.recv(); } - let mut try = 0; + let mut r#try = 0; loop { select! { recv(c32.rx()) -> v => { @@ -464,8 +461,8 @@ mod nonblock { break; } default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("i32sender buffer={}", buffer); panic!("fail"); } @@ -478,13 +475,13 @@ mod nonblock { } go!(c64, sync, i64receiver(c64, sync)); - let mut try = 0; + let mut r#try = 0; loop { select! { send(c64.tx(), 123456) -> _ => break, default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("i64receiver buffer={}", buffer); panic!("fail") } @@ -497,7 +494,7 @@ mod nonblock { if buffer > 0 { sync.recv(); } - let mut try = 0; + let mut r#try = 0; loop { select! { recv(c64.rx()) -> v => { @@ -507,8 +504,8 @@ mod nonblock { break; } default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("i64sender buffer={}", buffer); panic!("fail"); } @@ -521,13 +518,13 @@ mod nonblock { } go!(cb, sync, breceiver(cb, sync)); - let mut try = 0; + let mut r#try = 0; loop { select! { send(cb.tx(), true) -> _ => break, default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("breceiver buffer={}", buffer); panic!("fail") } @@ -540,7 +537,7 @@ mod nonblock { if buffer > 0 { sync.recv(); } - let mut try = 0; + let mut r#try = 0; loop { select! { recv(cb.rx()) -> v => { @@ -550,8 +547,8 @@ mod nonblock { break; } default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("bsender buffer={}", buffer); panic!("fail"); } @@ -564,13 +561,13 @@ mod nonblock { } go!(cs, sync, sreceiver(cs, sync)); - let mut try = 0; + let mut r#try = 0; loop { select! { send(cs.tx(), "hello".to_string()) -> _ => break, default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("sreceiver buffer={}", buffer); panic!("fail") } @@ -583,7 +580,7 @@ mod nonblock { if buffer > 0 { sync.recv(); } - let mut try = 0; + let mut r#try = 0; loop { select! { recv(cs.rx()) -> v => { @@ -593,8 +590,8 @@ mod nonblock { break; } default => { - try += 1; - if try > MAX_TRIES { + r#try += 1; + if r#try > MAX_TRIES { println!("ssender buffer={}", buffer); panic!("fail"); } 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/Cargo.toml b/crossbeam-deque/Cargo.toml index f6befeb1f..a38380997 100644 --- a/crossbeam-deque/Cargo.toml +++ b/crossbeam-deque/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-deque" # - Create "crossbeam-deque-X.Y.Z" git tag version = "0.7.3" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -23,7 +24,7 @@ default = ["std"] std = ["crossbeam-epoch/std", "crossbeam-utils/std"] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" [dependencies.crossbeam-epoch] version = "0.8" 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 cfdf85820..907dd0c29 100644 --- a/crossbeam-deque/src/deque.rs +++ b/crossbeam-deque/src/deque.rs @@ -8,8 +8,8 @@ use std::ptr; use std::sync::atomic::{self, AtomicIsize, AtomicPtr, AtomicUsize, Ordering}; use std::sync::Arc; -use epoch::{Atomic, Owned}; -use utils::{Backoff, CachePadded}; +use crate::epoch::{self, Atomic, Owned}; +use crate::utils::{Backoff, CachePadded}; // Minimum buffer capacity. const MIN_CAP: usize = 64; @@ -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 7e6a1ebbb..4195c1aed 100644 --- a/crossbeam-deque/src/lib.rs +++ b/crossbeam-deque/src/lib.rs @@ -86,19 +86,17 @@ //! [`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 deque::{Injector, Steal, Stealer, Worker}; + pub use crate::deque::{Injector, Steal, Stealer, Worker}; } } diff --git a/crossbeam-deque/tests/fifo.rs b/crossbeam-deque/tests/fifo.rs index 4a3216eb5..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 deque::Steal::{Empty, Success}; -use deque::Worker; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::Worker; +use crossbeam_utils::thread::scope; use rand::Rng; -use utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/injector.rs b/crossbeam-deque/tests/injector.rs index 069215399..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 deque::Steal::{Empty, Success}; -use deque::{Injector, Worker}; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::{Injector, Worker}; +use crossbeam_utils::thread::scope; use rand::Rng; -use utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/lifo.rs b/crossbeam-deque/tests/lifo.rs index a44edfe44..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 deque::Steal::{Empty, Success}; -use deque::Worker; +use crossbeam_deque::Steal::{Empty, Success}; +use crossbeam_deque::Worker; +use crossbeam_utils::thread::scope; use rand::Rng; -use utils::thread::scope; #[test] fn smoke() { diff --git a/crossbeam-deque/tests/steal.rs b/crossbeam-deque/tests/steal.rs index 3e874df15..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 deque::Steal::Success; -use deque::{Injector, Worker}; +use crossbeam_deque::Steal::Success; +use crossbeam_deque::{Injector, Worker}; #[test] fn steal_fifo() { diff --git a/crossbeam-epoch/Cargo.toml b/crossbeam-epoch/Cargo.toml index 91502c5f3..82a1b03e0 100644 --- a/crossbeam-epoch/Cargo.toml +++ b/crossbeam-epoch/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-epoch" # - Create "crossbeam-epoch-X.Y.Z" git tag version = "0.8.2" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -36,8 +37,8 @@ nightly = ["crossbeam-utils/nightly"] sanitize = [] # Makes it more likely to trigger any potential data races. [dependencies] -cfg-if = "0.1.2" -memoffset = "0.5" +cfg-if = "0.1.10" +memoffset = "0.5.1" [dependencies.crossbeam-utils] version = "0.7" 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 e3693e74a..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 epoch::Owned; +use crossbeam_epoch::{self as epoch, Owned}; +use crossbeam_utils::thread::scope; use test::Bencher; -use 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 156d4b091..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 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 4b26f2239..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 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 12f126312..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 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 3bac1d50b..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 epoch::{Atomic, Owned}; -use 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 69107e695..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 crate::guard::Guard; use crossbeam_utils::atomic::AtomicConsume; -use guard::Guard; /// 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 1817d9ada..50ef96830 100644 --- a/crossbeam-epoch/src/collector.rs +++ b/crossbeam-epoch/src/collector.rs @@ -15,8 +15,8 @@ use alloc::sync::Arc; use core::fmt; -use guard::Guard; -use internal::{Global, Local}; +use crate::guard::Guard; +use crate::internal::{Global, Local}; /// An epoch-based garbage collector. pub struct Collector { @@ -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 { .. }") } } @@ -110,7 +110,7 @@ mod tests { use crossbeam_utils::thread; - use {Collector, Owned}; + use crate::{Collector, Owned}; const NUM_THREADS: usize = 8; diff --git a/crossbeam-epoch/src/default.rs b/crossbeam-epoch/src/default.rs index 870e590fa..1deac2114 100644 --- a/crossbeam-epoch/src/default.rs +++ b/crossbeam-epoch/src/default.rs @@ -4,8 +4,9 @@ //! is registered in the default collector. If initialized, the thread's participant will get //! destructed on thread exit, which in turn unregisters the thread. -use collector::{Collector, LocalHandle}; -use guard::Guard; +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 df18cb118..aa470e4dc 100644 --- a/crossbeam-epoch/src/guard.rs +++ b/crossbeam-epoch/src/guard.rs @@ -1,10 +1,12 @@ use core::fmt; use core::mem; -use atomic::Shared; -use collector::Collector; -use deferred::Deferred; -use internal::Local; +use scopeguard::defer; + +use crate::atomic::Shared; +use crate::collector::Collector; +use crate::deferred::Deferred; +use crate::internal::Local; /// A guard that keeps the current thread pinned. /// @@ -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 3e7820ae5..b30038734 100644 --- a/crossbeam-epoch/src/internal.rs +++ b/crossbeam-epoch/src/internal.rs @@ -43,14 +43,15 @@ use core::sync::atomic::Ordering; use core::{fmt, ptr}; use crossbeam_utils::CachePadded; +use memoffset::offset_of; -use atomic::{Owned, Shared}; -use collector::{Collector, LocalHandle}; -use deferred::Deferred; -use epoch::{AtomicEpoch, Epoch}; -use guard::{unprotected, Guard}; -use sync::list::{Entry, IsElement, IterError, List}; -use sync::queue::Queue; +use crate::atomic::{Owned, Shared}; +use crate::collector::{Collector, LocalHandle}; +use crate::deferred::Deferred; +use crate::epoch::{AtomicEpoch, Epoch}; +use crate::guard::{unprotected, Guard}; +use crate::sync::list::{Entry, IsElement, IterError, List}; +use crate::sync::queue::Queue; /// Maximum number of objects a bag can contain. #[cfg(not(feature = "sanitize"))] @@ -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 8e8899ea2..57aea92f9 100644 --- a/crossbeam-epoch/src/sync/list.rs +++ b/crossbeam-epoch/src/sync/list.rs @@ -6,7 +6,7 @@ use core::marker::PhantomData; use core::sync::atomic::Ordering::{Acquire, Relaxed, Release}; -use {unprotected, Atomic, Guard, Shared}; +use crate::{unprotected, Atomic, Guard, Shared}; /// An entry in a linked list. /// @@ -66,7 +66,7 @@ pub struct Entry { /// pub trait IsElement { /// Returns a reference to this element's `Entry`. - fn entry_of(&T) -> &Entry; + fn entry_of(_: &T) -> &Entry; /// Given a reference to an element's entry, returns that element. /// @@ -80,7 +80,7 @@ pub trait IsElement { /// /// The caller has to guarantee that the `Entry` is called with was retrieved from an instance /// of the element type (`T`). - unsafe fn element_of(&Entry) -> &T; + unsafe fn element_of(_: &Entry) -> &T; /// The function that is called when an entry is unlinked from list. /// @@ -88,7 +88,7 @@ pub trait IsElement { /// /// The caller has to guarantee that the `Entry` is called with was retrieved from an instance /// of the element type (`T`). - unsafe fn finalize(&Entry, &Guard); + unsafe fn finalize(_: &Entry, _: &Guard); } /// A lock-free, intrusive linked list of type `T`. @@ -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 {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 71257b293..98ef667b5 100644 --- a/crossbeam-epoch/src/sync/queue.rs +++ b/crossbeam-epoch/src/sync/queue.rs @@ -13,7 +13,7 @@ use core::sync::atomic::Ordering::{Acquire, Relaxed, Release}; use crossbeam_utils::CachePadded; -use {unprotected, Atomic, Guard, Owned, Shared}; +use crate::{unprotected, Atomic, Guard, Owned, Shared}; // The representation here is a singly-linked list, with a sentinel node at the front. In general // the `tail` pointer may lag behind the actual tail. Non-sentinel nodes are either all `Data` or @@ -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); @@ -206,7 +206,7 @@ impl Drop for Queue { mod test { use super::*; use crossbeam_utils::thread; - use pin; + use crate::pin; struct Queue { queue: super::Queue, diff --git a/crossbeam-queue/Cargo.toml b/crossbeam-queue/Cargo.toml index abe11bccc..0ded97738 100644 --- a/crossbeam-queue/Cargo.toml +++ b/crossbeam-queue/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-queue" # - Create "crossbeam-queue-X.Y.Z" git tag version = "0.2.2" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0 AND BSD-2-Clause" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -33,7 +34,7 @@ alloc = [] nightly = [] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" [dependencies.crossbeam-utils] version = "0.7" 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 b3b354187..c27e196c8 100644 --- a/crossbeam-queue/src/array_queue.rs +++ b/crossbeam-queue/src/array_queue.rs @@ -17,7 +17,7 @@ use core::sync::atomic::{self, AtomicUsize, Ordering}; use crossbeam_utils::{Backoff, CachePadded}; -use err::{PopError, PushError}; +use crate::err::{PopError, PushError}; /// A slot in a queue. struct Slot { @@ -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 f32e8dd6c..2ddbc5ef4 100644 --- a/crossbeam-queue/src/seg_queue.rs +++ b/crossbeam-queue/src/seg_queue.rs @@ -8,7 +8,7 @@ use core::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}; use crossbeam_utils::{Backoff, CachePadded}; -use err::PopError; +use crate::err::PopError; // Bits indicating the state of a slot: // * If a value has been written into the slot, `WRITE` is set. @@ -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/Cargo.toml b/crossbeam-skiplist/Cargo.toml index 90f010b5a..3c1fbb369 100644 --- a/crossbeam-skiplist/Cargo.toml +++ b/crossbeam-skiplist/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-skiplist" # - Create "crossbeam-skiplist-X.Y.Z" git tag version = "0.0.0" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -33,7 +34,7 @@ alloc = ["crossbeam-epoch/alloc"] nightly = ["crossbeam-epoch/nightly", "crossbeam-utils/nightly"] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" [dependencies.crossbeam-epoch] version = "0.8" 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 f22e490f0..3ccb0932a 100644 --- a/crossbeam-skiplist/src/base.rs +++ b/crossbeam-skiplist/src/base.rs @@ -10,9 +10,8 @@ use core::ops::{Bound, Deref, Index, RangeBounds}; use core::ptr; use core::sync::atomic::{fence, AtomicUsize, Ordering}; -use epoch::{self, Atomic, Collector, Guard, Shared}; -use scopeguard; -use utils::CachePadded; +use crate::epoch::{self, Atomic, Collector, Guard, Shared}; +use crate::utils::CachePadded; /// Number of bits needed to store height. const HEIGHT_BITS: usize = 5; @@ -266,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) @@ -278,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]`. @@ -471,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) } @@ -487,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, @@ -832,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 { @@ -1049,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, @@ -1119,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)?; @@ -1132,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)?; @@ -1217,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 { .. }") } } @@ -1253,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, @@ -1325,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()) @@ -1395,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, } @@ -1456,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, @@ -1496,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()) @@ -1568,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>, @@ -1629,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))) @@ -1643,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)>), @@ -1726,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, @@ -1808,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) @@ -1825,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, @@ -1838,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, @@ -1846,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, @@ -1854,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) @@ -1988,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 2ab61b46c..566895fb9 100644 --- a/crossbeam-skiplist/src/lib.rs +++ b/crossbeam-skiplist/src/lib.rs @@ -1,27 +1,22 @@ //! 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)] - pub use base::SkipList; + pub use crate::base::SkipList; } } @@ -29,10 +24,10 @@ cfg_if! { if #[cfg(feature = "std")] { pub mod map; #[doc(inline)] - pub use map::SkipMap; + pub use crate::map::SkipMap; pub mod set; #[doc(inline)] - pub use set::SkipSet; + pub use crate::set::SkipSet; } } diff --git a/crossbeam-skiplist/src/map.rs b/crossbeam-skiplist/src/map.rs index f770b7b9a..079150f32 100644 --- a/crossbeam-skiplist/src/map.rs +++ b/crossbeam-skiplist/src/map.rs @@ -7,8 +7,8 @@ use std::mem::ManuallyDrop; use std::ops::{Bound, RangeBounds}; use std::ptr; -use base::{self, try_pin_loop}; -use epoch; +use crate::base::{self, try_pin_loop}; +use crate::epoch; /// A map based on a lock-free skip list. pub struct SkipMap { @@ -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 ca79ed858..b007d2a88 100644 --- a/crossbeam-skiplist/src/set.rs +++ b/crossbeam-skiplist/src/set.rs @@ -5,7 +5,7 @@ use std::fmt; use std::iter::FromIterator; use std::ops::{Bound, RangeBounds}; -use map; +use crate::map; /// A set based on a lock-free skip list. pub struct SkipSet { @@ -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 47a549b9b..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 skiplist::SkipList; +use crossbeam_epoch as epoch; +use crossbeam_skiplist::SkipList; #[test] fn new() { @@ -509,7 +507,7 @@ fn iter() { #[test] fn iter_range() { - use Bound::*; + use crate::Bound::*; let guard = &epoch::pin(); let s = SkipList::new(epoch::default_collector().clone()); let v = (0..10).map(|x| x * 10).collect::>(); diff --git a/crossbeam-skiplist/tests/map.rs b/crossbeam-skiplist/tests/map.rs index 0906a8e6e..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 skiplist::SkipMap; +use crossbeam_skiplist::SkipMap; #[test] fn smoke() { diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs index 719800c3a..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 skiplist::SkipSet; +use crossbeam_skiplist::SkipSet; #[test] fn smoke() { diff --git a/crossbeam-utils/Cargo.toml b/crossbeam-utils/Cargo.toml index 2b79281d5..29d35f887 100644 --- a/crossbeam-utils/Cargo.toml +++ b/crossbeam-utils/Cargo.toml @@ -6,6 +6,7 @@ name = "crossbeam-utils" # - Create "crossbeam-utils-X.Y.Z" git tag version = "0.7.2" authors = ["The Crossbeam Project Developers"] +edition = "2018" license = "MIT/Apache-2.0" readme = "README.md" repository = "https://github.com/crossbeam-rs/crossbeam" @@ -29,7 +30,7 @@ std = ["lazy_static"] nightly = [] [dependencies] -cfg-if = "0.1.2" +cfg-if = "0.1.10" lazy_static = { version = "1.1.0", optional = true } [build-dependencies] 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/atomic/seq_lock.rs b/crossbeam-utils/src/atomic/seq_lock.rs index e00f29b37..caea10846 100644 --- a/crossbeam-utils/src/atomic/seq_lock.rs +++ b/crossbeam-utils/src/atomic/seq_lock.rs @@ -1,7 +1,7 @@ use core::mem; use core::sync::atomic::{self, AtomicUsize, Ordering}; -use Backoff; +use crate::Backoff; /// A simple stamped lock. pub struct SeqLock { diff --git a/crossbeam-utils/src/atomic/seq_lock_wide.rs b/crossbeam-utils/src/atomic/seq_lock_wide.rs index 857c074f5..150ddaf98 100644 --- a/crossbeam-utils/src/atomic/seq_lock_wide.rs +++ b/crossbeam-utils/src/atomic/seq_lock_wide.rs @@ -1,6 +1,6 @@ use core::sync::atomic::{self, AtomicUsize, Ordering}; -use Backoff; +use crate::Backoff; /// A simple stamped lock. /// 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 e971ad111..e76934b99 100644 --- a/crossbeam-utils/src/lib.rs +++ b/crossbeam-utils/src/lib.rs @@ -26,30 +26,23 @@ //! [`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; mod cache_padded; -pub use cache_padded::CachePadded; +pub use crate::cache_padded::CachePadded; mod backoff; -pub use backoff::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 bd269d158..b6581a483 100644 --- a/crossbeam-utils/src/sync/sharded_lock.rs +++ b/crossbeam-utils/src/sync/sharded_lock.rs @@ -9,7 +9,8 @@ use std::sync::{LockResult, PoisonError, TryLockError, TryLockResult}; use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::thread::{self, ThreadId}; -use CachePadded; +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 5c8c2058e..ab51322a5 100644 --- a/crossbeam-utils/src/thread.rs +++ b/crossbeam-utils/src/thread.rs @@ -121,7 +121,8 @@ use std::panic; use std::sync::{Arc, Mutex}; use std::thread; -use sync::WaitGroup; +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 6e0ecf36a..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,40 +55,39 @@ 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 _queue::crossbeam_queue as queue; + pub use crate::_queue::crossbeam_queue as queue; } } cfg_if! { if #[cfg(feature = "std")] { mod _deque { - pub extern crate crossbeam_deque; + pub use crossbeam_deque; } #[doc(inline)] - pub use _deque::crossbeam_deque as deque; + 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 _channel::crossbeam_channel as channel; + 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 _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() {