Skip to content

Commit

Permalink
Deny warnings for doc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 24, 2020
1 parent 9d57966 commit 7cb7218
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 63 deletions.
10 changes: 3 additions & 7 deletions crossbeam-channel/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
/// Using an `after` channel for timeouts:
///
/// ```
/// # fn main() {
/// use std::time::Duration;
/// use crossbeam_channel::{after, select, unbounded};
///
Expand All @@ -147,7 +146,6 @@ pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
/// recv(r) -> msg => println!("received {:?}", msg),
/// recv(after(timeout)) -> _ => println!("timed out"),
/// }
/// # }
/// ```
///
/// When the message gets sent:
Expand Down Expand Up @@ -187,9 +185,8 @@ pub fn after(duration: Duration) -> Receiver<Instant> {
/// Using a `never` channel to optionally add a timeout to [`select!`]:
///
/// ```
/// # fn main() {
/// use std::thread;
/// use std::time::{Duration, Instant};
/// use std::time::Duration;
/// use crossbeam_channel::{after, select, never, unbounded};
///
/// let (s, r) = unbounded();
Expand All @@ -211,7 +208,6 @@ pub fn after(duration: Duration) -> Receiver<Instant> {
/// recv(r) -> msg => assert_eq!(msg, Ok(1)),
/// recv(timeout) -> _ => println!("timed out"),
/// }
/// # }
/// ```
///
/// [`select!`]: macro.select.html
Expand Down Expand Up @@ -597,9 +593,9 @@ impl<T> fmt::Debug for Sender<T> {
/// let (s, r) = unbounded();
///
/// thread::spawn(move || {
/// s.send(1);
/// let _ = s.send(1);
/// thread::sleep(Duration::from_secs(1));
/// s.send(2);
/// let _ = s.send(2);
/// });
///
/// assert_eq!(r.recv(), Ok(1)); // Received immediately.
Expand Down
14 changes: 7 additions & 7 deletions crossbeam-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
//! It's also possible to share senders and receivers by reference:
//!
//! ```
//! # fn main() {
//! use std::thread;
//! use crossbeam_channel::bounded;
//! use crossbeam_utils::thread::scope;
//!
Expand All @@ -140,7 +138,6 @@
//! s.send(1).unwrap();
//! r.recv().unwrap();
//! }).unwrap();
//! # }
//! ```
//!
//! # Disconnection
Expand Down Expand Up @@ -269,7 +266,6 @@
//! An example of receiving a message from two channels:
//!
//! ```
//! # fn main() {
//! use std::thread;
//! use std::time::Duration;
//! use crossbeam_channel::{select, unbounded};
Expand All @@ -286,7 +282,6 @@
//! recv(r2) -> msg => assert_eq!(msg, Ok(20)),
//! default(Duration::from_secs(1)) => println!("timed out"),
//! }
//! # }
//! ```
//!
//! If you need to select over a dynamically created list of channel operations, use [`Select`]
Expand All @@ -306,7 +301,6 @@
//! An example that prints elapsed time every 50 milliseconds for the duration of 1 second:
//!
//! ```
//! # fn main() {
//! use std::time::{Duration, Instant};
//! use crossbeam_channel::{after, select, tick};
//!
Expand All @@ -320,7 +314,6 @@
//! recv(timeout) -> _ => break,
//! }
//! }
//! # }
//! ```
//!
//! [`std::sync::mpsc`]: https://doc.rust-lang.org/std/sync/mpsc/index.html
Expand All @@ -338,6 +331,13 @@
//! [`Sender`]: struct.Sender.html
//! [`Receiver`]: struct.Receiver.html
#![doc(test(
no_crate_inject,
attr(
deny(warnings, rust_2018_idioms),
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
5 changes: 0 additions & 5 deletions crossbeam-channel/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ impl<'a> Select<'a> {
/// # Examples
///
/// ```
/// use std::thread;
/// use crossbeam_channel::{unbounded, Select};
///
/// let (s, r) = unbounded::<i32>();
Expand All @@ -638,7 +637,6 @@ impl<'a> Select<'a> {
/// # Examples
///
/// ```
/// use std::thread;
/// use crossbeam_channel::{unbounded, Select};
///
/// let (s, r) = unbounded::<i32>();
Expand Down Expand Up @@ -669,7 +667,6 @@ impl<'a> Select<'a> {
/// # Examples
///
/// ```
/// use std::thread;
/// use crossbeam_channel::{unbounded, Select};
///
/// let (s1, r1) = unbounded::<i32>();
Expand Down Expand Up @@ -728,7 +725,6 @@ impl<'a> Select<'a> {
/// # Examples
///
/// ```
/// use std::thread;
/// use crossbeam_channel::{unbounded, Select};
///
/// let (s1, r1) = unbounded();
Expand Down Expand Up @@ -874,7 +870,6 @@ impl<'a> Select<'a> {
/// # Examples
///
/// ```
/// use std::thread;
/// use crossbeam_channel::{unbounded, Select};
///
/// let (s1, r1) = unbounded();
Expand Down
9 changes: 0 additions & 9 deletions crossbeam-channel/src/select_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,6 @@ macro_rules! crossbeam_channel_internal {
/// Block until a send or a receive operation is selected:
///
/// ```
/// # fn main() {
/// use std::thread;
/// use crossbeam_channel::{select, unbounded};
///
/// let (s1, r1) = unbounded();
Expand All @@ -1092,13 +1090,11 @@ macro_rules! crossbeam_channel_internal {
/// assert_eq!(r2.recv(), Ok(20));
/// }
/// }
/// # }
/// ```
///
/// Select from a set of operations without blocking:
///
/// ```
/// # fn main() {
/// use std::thread;
/// use std::time::Duration;
/// use crossbeam_channel::{select, unbounded};
Expand All @@ -1121,13 +1117,11 @@ macro_rules! crossbeam_channel_internal {
/// recv(r2) -> msg => panic!(),
/// default => println!("not ready"),
/// }
/// # }
/// ```
///
/// Select over a set of operations with a timeout:
///
/// ```
/// # fn main() {
/// use std::thread;
/// use std::time::Duration;
/// use crossbeam_channel::{select, unbounded};
Expand All @@ -1150,13 +1144,11 @@ macro_rules! crossbeam_channel_internal {
/// recv(r2) -> msg => panic!(),
/// default(Duration::from_millis(100)) => println!("timed out"),
/// }
/// # }
/// ```
///
/// Optionally add a receive operation to `select!` using [`never`]:
///
/// ```
/// # fn main() {
/// use std::thread;
/// use std::time::Duration;
/// use crossbeam_channel::{select, never, unbounded};
Expand All @@ -1181,7 +1173,6 @@ macro_rules! crossbeam_channel_internal {
/// recv(r1) -> msg => panic!(),
/// recv(r2.unwrap_or(&never())) -> msg => assert_eq!(msg, Ok(20)),
/// }
/// # }
/// ```
///
/// To optionally add a timeout to `select!`, see the [example] for [`never`].
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-deque/src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ impl<T> Stealer<T> {
/// let s = w1.stealer();
/// let w2 = Worker::new_fifo();
///
/// s.steal_batch(&w2);
/// let _ = s.steal_batch(&w2);
/// assert_eq!(w2.pop(), Some(1));
/// assert_eq!(w2.pop(), Some(2));
/// ```
Expand Down Expand Up @@ -1384,7 +1384,7 @@ impl<T> Injector<T> {
/// q.push(4);
///
/// let w = Worker::new_fifo();
/// q.steal_batch(&w);
/// let _ = q.steal_batch(&w);
/// assert_eq!(w.pop(), Some(1));
/// assert_eq!(w.pop(), Some(2));
/// ```
Expand Down
9 changes: 8 additions & 1 deletion crossbeam-deque/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
//! An implementation of this work-stealing strategy:
//!
//! ```
//! use crossbeam_deque::{Injector, Steal, Stealer, Worker};
//! use crossbeam_deque::{Injector, Stealer, Worker};
//! use std::iter;
//!
//! fn find_task<T>(
Expand Down Expand Up @@ -86,6 +86,13 @@
//! [`steal_batch()`]: struct.Stealer.html#method.steal_batch
//! [`steal_batch_and_pop()`]: struct.Stealer.html#method.steal_batch_and_pop
#![doc(test(
no_crate_inject,
attr(
deny(warnings, rust_2018_idioms),
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
10 changes: 5 additions & 5 deletions crossbeam-epoch/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<T> Atomic<T> {
/// # Examples
///
/// ```
/// use crossbeam_epoch::{self as epoch, Atomic, Owned, Shared};
/// use crossbeam_epoch::{Atomic, Owned, Shared};
/// use std::sync::atomic::Ordering::SeqCst;
///
/// let a = Atomic::new(1234);
Expand All @@ -247,7 +247,7 @@ impl<T> Atomic<T> {
/// # Examples
///
/// ```
/// use crossbeam_epoch::{self as epoch, Atomic, Owned, Shared};
/// use crossbeam_epoch::{self as epoch, Atomic, Shared};
/// use std::sync::atomic::Ordering::SeqCst;
///
/// let a = Atomic::new(1234);
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<T> Atomic<T> {
/// let a = Atomic::new(1234);
///
/// let guard = &epoch::pin();
/// let mut curr = a.load(SeqCst, guard);
/// let curr = a.load(SeqCst, guard);
/// let res1 = a.compare_and_set(curr, Shared::null(), SeqCst, guard);
/// let res2 = a.compare_and_set(curr, Owned::new(5678), SeqCst, guard);
/// ```
Expand Down Expand Up @@ -689,7 +689,7 @@ impl<T> Owned<T> {
/// # Examples
///
/// ```
/// use crossbeam_epoch::{self as epoch, Owned};
/// use crossbeam_epoch::Owned;
///
/// let o = Owned::new(1234);
/// let b: Box<i32> = o.into_box();
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl<T> From<*const T> for Shared<'_, T> {
/// ```
/// use crossbeam_epoch::Shared;
///
/// let p = unsafe { Shared::from(Box::into_raw(Box::new(1234)) as *const _) };
/// let p = Shared::from(Box::into_raw(Box::new(1234)) as *const _);
/// assert!(!p.is_null());
/// ```
fn from(raw: *const T) -> Self {
Expand Down
16 changes: 6 additions & 10 deletions crossbeam-epoch/src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::internal::Local;
/// For example:
///
/// ```
/// use crossbeam_epoch::{self as epoch, Atomic, Owned};
/// use crossbeam_epoch::{self as epoch, Atomic};
/// use std::sync::atomic::Ordering::SeqCst;
///
/// // Create a heap-allocated number.
Expand Down Expand Up @@ -289,11 +289,9 @@ impl Guard {
/// use crossbeam_epoch as epoch;
///
/// let guard = &epoch::pin();
/// unsafe {
/// guard.defer(move || {
/// println!("This better be printed as soon as possible!");
/// });
/// }
/// guard.defer(move || {
/// println!("This better be printed as soon as possible!");
/// });
/// guard.flush();
/// ```
///
Expand All @@ -318,8 +316,6 @@ impl Guard {
/// ```
/// use crossbeam_epoch::{self as epoch, Atomic};
/// use std::sync::atomic::Ordering::SeqCst;
/// use std::thread;
/// use std::time::Duration;
///
/// let a = Atomic::new(777);
/// let mut guard = epoch::pin();
Expand Down Expand Up @@ -407,8 +403,8 @@ impl Guard {
/// ```
/// use crossbeam_epoch as epoch;
///
/// let mut guard1 = epoch::pin();
/// let mut guard2 = epoch::pin();
/// let guard1 = epoch::pin();
/// let guard2 = epoch::pin();
/// assert!(guard1.collector() == guard2.collector());
/// ```
///
Expand Down
7 changes: 7 additions & 0 deletions crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
//! [`pin`]: fn.pin.html
//! [`defer`]: struct.Guard.html#method.defer
#![doc(test(
no_crate_inject,
attr(
deny(warnings, rust_2018_idioms),
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![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))]
Expand Down
9 changes: 7 additions & 2 deletions crossbeam-epoch/src/sync/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ impl<T> Queue<T> {
/// 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<'_, Node<T>>, new: Shared<'_, Node<T>>, guard: &Guard) -> bool {
fn push_internal(
&self,
onto: Shared<'_, Node<T>>,
new: Shared<'_, Node<T>>,
guard: &Guard,
) -> bool {
// is `onto` the actual tail?
let o = unsafe { onto.deref() };
let next = o.next.load(Acquire, guard);
Expand Down Expand Up @@ -205,8 +210,8 @@ impl<T> Drop for Queue<T> {
#[cfg(test)]
mod test {
use super::*;
use crossbeam_utils::thread;
use crate::pin;
use crossbeam_utils::thread;

struct Queue<T> {
queue: super::Queue<T>,
Expand Down
Loading

0 comments on commit 7cb7218

Please sign in to comment.