提交 82784cb8 编写于 作者: K Kevin Butler

libcore: deny warnings in doctests

上级 bbf964af
......@@ -76,6 +76,7 @@
//! a trait method that was originally defined to take `&self`.
//!
//! ```
//! # #![allow(dead_code)]
//! use std::cell::RefCell;
//!
//! struct Graph {
......@@ -125,6 +126,7 @@
//! }
//!
//! struct RcBox<T> {
//! # #[allow(dead_code)]
//! value: T,
//! refcount: Cell<usize>
//! }
......@@ -776,6 +778,7 @@ fn deref_mut(&mut self) -> &mut T {
/// use std::cell::UnsafeCell;
/// use std::marker::Sync;
///
/// # #[allow(dead_code)]
/// struct NotThreadSafe<T> {
/// value: UnsafeCell<T>,
/// }
......
......@@ -140,8 +140,6 @@ unsafe fn from_i8_unchecked(v: i8) -> 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.
......@@ -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);
///
......
......@@ -15,6 +15,7 @@
//! that define a set of options:
//!
//! ```
//! # #[allow(dead_code)]
//! struct SomeOptions {
//! foo: i32,
//! bar: f32,
......@@ -24,6 +25,7 @@
//! How can we define some default values? You can use `Default`:
//!
//! ```
//! # #[allow(dead_code)]
//! #[derive(Default)]
//! struct SomeOptions {
//! foo: i32,
......@@ -40,6 +42,7 @@
//! If you have your own type, you need to implement `Default` yourself:
//!
//! ```
//! # #![allow(dead_code)]
//! enum Kind {
//! A,
//! B,
......@@ -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,
......@@ -88,6 +92,7 @@
/// # Examples
///
/// ```
/// # #[allow(dead_code)]
/// #[derive(Default)]
/// struct SomeOptions {
/// foo: i32,
......@@ -114,6 +119,7 @@ pub trait Default: Sized {
/// Making your own:
///
/// ```
/// # #[allow(dead_code)]
/// enum Kind {
/// A,
/// B,
......
......@@ -45,6 +45,7 @@
//!
//! struct Person {
//! id: u32,
//! # #[allow(dead_code)]
//! name: String,
//! phone: u64,
//! }
......
......@@ -334,6 +334,7 @@
/// 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
......@@ -372,6 +373,7 @@
/// ```
/// 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);
......
......@@ -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));
//! ```
......@@ -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());
/// ```
......@@ -709,6 +710,7 @@ fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter> where
/// 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));
///
......@@ -2695,7 +2697,7 @@ fn next_back(&mut self) -> Option<I::Item> { (**self).next_back() }
///
/// ```
/// // a finite range knows exactly how many times it will iterate
/// let five = (0..5);
/// let five = 0..5;
///
/// assert_eq!(5, five.len());
/// ```
......@@ -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());
/// ```
......
......@@ -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)]
......
......@@ -247,6 +247,7 @@
/// Match arms:
///
/// ```
/// # #[allow(dead_code)]
/// fn foo(x: Option<i32>) {
/// match x {
/// Some(n) if n >= 0 => println!("Some(Non-negative)"),
......@@ -260,6 +261,7 @@
/// 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"); }
......
......@@ -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);
///
......@@ -106,6 +107,7 @@ pub trait Unsize<T: ?Sized> {
/// `struct` can be `Copy`:
///
/// ```
/// # #[allow(dead_code)]
/// struct Point {
/// x: i32,
/// y: i32,
......@@ -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>,
......@@ -303,6 +306,7 @@ fn default() -> $t<T> {
/// ```
/// use std::marker::PhantomData;
///
/// # #[allow(dead_code)]
/// struct Slice<'a, T:'a> {
/// start: *const T,
/// end: *const T,
......@@ -323,6 +327,7 @@ fn default() -> $t<T> {
/// mismatches by enforcing types in the method implementations:
///
/// ```
/// # #![allow(dead_code)]
/// # trait ResType { fn foo(&self); }
/// # struct ParamType;
/// # mod foreign_lib {
......@@ -393,6 +398,8 @@ unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
/// #![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"); }
......
......@@ -92,6 +92,7 @@
/// 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
......@@ -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>());
......@@ -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));
......@@ -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> {
......
......@@ -947,6 +947,7 @@ fn shr(self, other: $f) -> $t {
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo += Foo;
......@@ -996,6 +997,7 @@ fn add_assign(&mut self, other: $t) { *self += other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo -= Foo;
......@@ -1045,6 +1047,7 @@ fn sub_assign(&mut self, other: $t) { *self -= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo *= Foo;
......@@ -1094,6 +1097,7 @@ fn mul_assign(&mut self, other: $t) { *self *= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo /= Foo;
......@@ -1143,6 +1147,7 @@ fn div_assign(&mut self, other: $t) { *self /= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo %= Foo;
......@@ -1192,6 +1197,7 @@ fn rem_assign(&mut self, other: $t) { *self %= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo &= Foo;
......@@ -1241,6 +1247,7 @@ fn bitand_assign(&mut self, other: $t) { *self &= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo |= Foo;
......@@ -1290,6 +1297,7 @@ fn bitor_assign(&mut self, other: $t) { *self |= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo ^= Foo;
......@@ -1339,6 +1347,7 @@ fn bitxor_assign(&mut self, other: $t) { *self ^= other }
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo <<= Foo;
......@@ -1407,6 +1416,7 @@ fn shl_assign(&mut self, other: $f) {
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo >>= Foo;
......
......@@ -275,6 +275,7 @@ pub fn as_mut(&mut self) -> Option<&mut T> {
///
/// ```
/// #![feature(as_slice)]
/// # #![allow(deprecated)]
///
/// let mut x = Some("Diamonds");
/// {
......
......@@ -16,6 +16,7 @@
//! and containing an error value.
//!
//! ```
//! # #[allow(dead_code)]
//! enum Result<T, E> {
//! Ok(T),
//! Err(E)
......@@ -104,6 +105,7 @@
//! something like this:
//!
//! ```no_run
//! # #![allow(unused_must_use)] // \o/
//! use std::fs::File;
//! use std::io::prelude::*;
//!
......@@ -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"));
......@@ -160,6 +163,7 @@
//! It replaces this:
//!
//! ```
//! # #![allow(dead_code)]
//! use std::fs::File;
//! use std::io::prelude::*;
//! use std::io;
......@@ -189,6 +193,7 @@
//! With this:
//!
//! ```
//! # #![allow(dead_code)]
//! use std::fs::File;
//! use std::io::prelude::*;
//! use std::io;
......@@ -422,6 +427,7 @@ pub fn as_slice(&self) -> &[T] {
///
/// ```
/// #![feature(as_slice)]
/// # #![allow(deprecated)]
///
/// let mut x: Result<&str, u32> = Ok("Gold");
/// {
......
......@@ -142,8 +142,6 @@ impl Utf8Error {
/// Basic usage:
///
/// ```
/// #![feature(utf8_error)]
///
/// use std::str;
///
/// // some invalid bytes, in a vector
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册