Skip to content

Commit

Permalink
libcore: deny warnings in doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryman committed Nov 12, 2015
1 parent bbf964a commit 82784cb
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/libcore/cell.rs
Expand Up @@ -76,6 +76,7 @@
//! a trait method that was originally defined to take `&self`.
//!
//! ```
//! # #![allow(dead_code)]
//! use std::cell::RefCell;
//!
//! struct Graph {
Expand Down Expand Up @@ -125,6 +126,7 @@
//! }
//!
//! struct RcBox<T> {
//! # #[allow(dead_code)]
//! value: T,
//! refcount: Cell<usize>
//! }
Expand Down Expand Up @@ -776,6 +778,7 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
/// use std::cell::UnsafeCell;
/// use std::marker::Sync;
///
/// # #[allow(dead_code)]
/// struct NotThreadSafe<T> {
/// value: UnsafeCell<T>,
/// }
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/cmp.rs
Expand Up @@ -140,8 +140,6 @@ impl Ordering {
/// This method can be used to reverse a comparison:
///
/// ```
/// use std::cmp::Ordering;
///
/// let mut data: &mut [_] = &mut [2, 10, 5, 8];
///
/// // sort the array from largest to smallest.
Expand Down Expand Up @@ -263,8 +261,6 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
/// # Examples
///
/// ```
/// use std::cmp::Ordering;
///
/// let result = 1.0 < 2.0;
/// assert_eq!(result, true);
///
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/default.rs
Expand Up @@ -15,6 +15,7 @@
//! that define a set of options:
//!
//! ```
//! # #[allow(dead_code)]
//! struct SomeOptions {
//! foo: i32,
//! bar: f32,
Expand All @@ -24,6 +25,7 @@
//! How can we define some default values? You can use `Default`:
//!
//! ```
//! # #[allow(dead_code)]
//! #[derive(Default)]
//! struct SomeOptions {
//! foo: i32,
Expand All @@ -40,6 +42,7 @@
//! If you have your own type, you need to implement `Default` yourself:
//!
//! ```
//! # #![allow(dead_code)]
//! enum Kind {
//! A,
//! B,
Expand All @@ -66,6 +69,7 @@
//! If you want to override a particular option, but still retain the other defaults:
//!
//! ```
//! # #[allow(dead_code)]
//! # #[derive(Default)]
//! # struct SomeOptions {
//! # foo: i32,
Expand All @@ -88,6 +92,7 @@ use marker::Sized;
/// # Examples
///
/// ```
/// # #[allow(dead_code)]
/// #[derive(Default)]
/// struct SomeOptions {
/// foo: i32,
Expand All @@ -114,6 +119,7 @@ pub trait Default: Sized {
/// Making your own:
///
/// ```
/// # #[allow(dead_code)]
/// enum Kind {
/// A,
/// B,
Expand Down
1 change: 1 addition & 0 deletions src/libcore/hash/mod.rs
Expand Up @@ -45,6 +45,7 @@
//!
//! struct Person {
//! id: u32,
//! # #[allow(dead_code)]
//! name: String,
//! phone: u64,
//! }
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/intrinsics.rs
Expand Up @@ -334,6 +334,7 @@ extern "rust-intrinsic" {
/// use std::mem;
/// use std::ptr;
///
/// # #[allow(dead_code)]
/// fn swap<T>(x: &mut T, y: &mut T) {
/// unsafe {
/// // Give ourselves some scratch space to work with
Expand Down Expand Up @@ -372,6 +373,7 @@ extern "rust-intrinsic" {
/// ```
/// use std::ptr;
///
/// # #[allow(dead_code)]
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
/// let mut dst = Vec::with_capacity(elts);
/// dst.set_len(elts);
Expand Down
8 changes: 5 additions & 3 deletions src/libcore/iter.rs
Expand Up @@ -241,6 +241,7 @@
//! method calls a closure on each element it iterates over:
//!
//! ```
//! # #![allow(unused_must_use)]
//! let v = vec![1, 2, 3, 4, 5];
//! v.iter().map(|x| println!("{}", x));
//! ```
Expand Down Expand Up @@ -419,7 +420,7 @@ pub trait Iterator {
///
/// ```
/// // an infinite iterator has no upper bound
/// let iter = (0..);
/// let iter = 0..;
///
/// assert_eq!((0, None), iter.size_hint());
/// ```
Expand Down Expand Up @@ -709,6 +710,7 @@ pub trait Iterator {
/// If you're doing some sort of side effect, prefer [`for`] to `map()`:
///
/// ```
/// # #![allow(unused_must_use)]
/// // don't do this:
/// (0..5).map(|x| println!("{}", x));
///
Expand Down Expand Up @@ -2695,7 +2697,7 @@ impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I {
///
/// ```
/// // a finite range knows exactly how many times it will iterate
/// let five = (0..5);
/// let five = 0..5;
///
/// assert_eq!(5, five.len());
/// ```
Expand Down Expand Up @@ -2761,7 +2763,7 @@ pub trait ExactSizeIterator: Iterator {
///
/// ```
/// // a finite range knows exactly how many times it will iterate
/// let five = (0..5);
/// let five = 0..5;
///
/// assert_eq!(5, five.len());
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Expand Up @@ -60,7 +60,7 @@
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
#![doc(test(no_crate_inject))]
#![doc(test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]

#![no_core]
#![allow(raw_pointer_derive)]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/macros.rs
Expand Up @@ -247,6 +247,7 @@ macro_rules! writeln {
/// Match arms:
///
/// ```
/// # #[allow(dead_code)]
/// fn foo(x: Option<i32>) {
/// match x {
/// Some(n) if n >= 0 => println!("Some(Non-negative)"),
Expand All @@ -260,6 +261,7 @@ macro_rules! writeln {
/// Iterators:
///
/// ```
/// # #[allow(dead_code)]
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
/// for i in 0.. {
/// if 3*i < i { panic!("u32 overflow"); }
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/marker.rs
Expand Up @@ -42,6 +42,7 @@ impl<T> !Send for *mut T { }
/// `?Sized` can be used to remove this bound if it is not appropriate.
///
/// ```
/// # #![allow(dead_code)]
/// struct Foo<T>(T);
/// struct Bar<T: ?Sized>(T);
///
Expand Down Expand Up @@ -106,6 +107,7 @@ pub trait Unsize<T: ?Sized> {
/// `struct` can be `Copy`:
///
/// ```
/// # #[allow(dead_code)]
/// struct Point {
/// x: i32,
/// y: i32,
Expand All @@ -115,6 +117,7 @@ pub trait Unsize<T: ?Sized> {
/// A `struct` can be `Copy`, and `i32` is `Copy`, so therefore, `Point` is eligible to be `Copy`.
///
/// ```
/// # #![allow(dead_code)]
/// # struct Point;
/// struct PointList {
/// points: Vec<Point>,
Expand Down Expand Up @@ -303,6 +306,7 @@ macro_rules! impls{
/// ```
/// use std::marker::PhantomData;
///
/// # #[allow(dead_code)]
/// struct Slice<'a, T:'a> {
/// start: *const T,
/// end: *const T,
Expand All @@ -323,6 +327,7 @@ macro_rules! impls{
/// mismatches by enforcing types in the method implementations:
///
/// ```
/// # #![allow(dead_code)]
/// # trait ResType { fn foo(&self); }
/// # struct ParamType;
/// # mod foreign_lib {
Expand Down Expand Up @@ -393,6 +398,8 @@ mod impls {
/// #![feature(reflect_marker)]
/// use std::marker::Reflect;
/// use std::any::Any;
///
/// # #[allow(dead_code)]
/// fn foo<T:Reflect+'static>(x: &T) {
/// let any: &Any = x;
/// if any.is::<u32>() { println!("u32"); }
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/mem.rs
Expand Up @@ -92,6 +92,7 @@ pub use intrinsics::transmute;
/// use std::mem;
/// use std::ptr;
///
/// # #[allow(dead_code)]
/// fn swap<T>(x: &mut T, y: &mut T) {
/// unsafe {
/// // Give ourselves some scratch space to work with
Expand Down Expand Up @@ -151,6 +152,7 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
/// # Examples
///
/// ```
/// # #![allow(deprecated)]
/// use std::mem;
///
/// assert_eq!(4, mem::min_align_of::<i32>());
Expand All @@ -167,6 +169,7 @@ pub fn min_align_of<T>() -> usize {
/// # Examples
///
/// ```
/// # #![allow(deprecated)]
/// use std::mem;
///
/// assert_eq!(4, mem::min_align_of_val(&5i32));
Expand Down Expand Up @@ -414,6 +417,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
/// `self`, allowing it to be returned:
///
/// ```
/// # #![allow(dead_code)]
/// use std::mem;
/// # struct Buffer<T> { buf: Vec<T> }
/// impl<T> Buffer<T> {
Expand Down
10 changes: 10 additions & 0 deletions src/libcore/ops.rs
Expand Up @@ -947,6 +947,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo += Foo;
Expand Down Expand Up @@ -996,6 +997,7 @@ add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo -= Foo;
Expand Down Expand Up @@ -1045,6 +1047,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo *= Foo;
Expand Down Expand Up @@ -1094,6 +1097,7 @@ mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo /= Foo;
Expand Down Expand Up @@ -1143,6 +1147,7 @@ div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo %= Foo;
Expand Down Expand Up @@ -1192,6 +1197,7 @@ rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo &= Foo;
Expand Down Expand Up @@ -1241,6 +1247,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo |= Foo;
Expand Down Expand Up @@ -1290,6 +1297,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo ^= Foo;
Expand Down Expand Up @@ -1339,6 +1347,7 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo <<= Foo;
Expand Down Expand Up @@ -1407,6 +1416,7 @@ shl_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo >>= Foo;
Expand Down
1 change: 1 addition & 0 deletions src/libcore/option.rs
Expand Up @@ -275,6 +275,7 @@ impl<T> Option<T> {
///
/// ```
/// #![feature(as_slice)]
/// # #![allow(deprecated)]
///
/// let mut x = Some("Diamonds");
/// {
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/result.rs
Expand Up @@ -16,6 +16,7 @@
//! and containing an error value.
//!
//! ```
//! # #[allow(dead_code)]
//! enum Result<T, E> {
//! Ok(T),
//! Err(E)
Expand Down Expand Up @@ -104,6 +105,7 @@
//! something like this:
//!
//! ```no_run
//! # #![allow(unused_must_use)] // \o/
//! use std::fs::File;
//! use std::io::prelude::*;
//!
Expand Down Expand Up @@ -143,6 +145,7 @@
//! # use std::fs::File;
//! # use std::io::prelude::*;
//! # use std::io;
//! # #[allow(dead_code)]
//! fn write_message() -> io::Result<()> {
//! let mut file = try!(File::create("valuable_data.txt"));
//! try!(file.write_all(b"important message"));
Expand All @@ -160,6 +163,7 @@
//! It replaces this:
//!
//! ```
//! # #![allow(dead_code)]
//! use std::fs::File;
//! use std::io::prelude::*;
//! use std::io;
Expand Down Expand Up @@ -189,6 +193,7 @@
//! With this:
//!
//! ```
//! # #![allow(dead_code)]
//! use std::fs::File;
//! use std::io::prelude::*;
//! use std::io;
Expand Down Expand Up @@ -422,6 +427,7 @@ impl<T, E> Result<T, E> {
///
/// ```
/// #![feature(as_slice)]
/// # #![allow(deprecated)]
///
/// let mut x: Result<&str, u32> = Ok("Gold");
/// {
Expand Down

0 comments on commit 82784cb

Please sign in to comment.