提交 ba402312 编写于 作者: A Alex Crichton

std: Deny most warnings in doctests

Allow a few specific ones but otherwise this helps ensure that our examples are
squeaky clean!

Closes #18199
上级 179719d4
......@@ -229,7 +229,6 @@
/// Iterators:
///
/// ```
/// # #![feature(core)]
/// 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"); }
......
......@@ -304,7 +304,6 @@ fn first<A, B>((a, _): (A, B)) -> A { a }
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
......@@ -335,7 +334,6 @@ pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
......@@ -362,7 +360,6 @@ pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>)
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
......@@ -388,7 +385,6 @@ pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a,
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
......@@ -471,7 +467,6 @@ pub fn clear(&mut self) { self.map.clear() }
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
///
/// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
......@@ -491,7 +486,6 @@ pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
///
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
......@@ -513,7 +507,6 @@ pub fn is_disjoint(&self, other: &HashSet<T, S>) -> bool {
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
///
/// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect();
......@@ -535,7 +528,6 @@ pub fn is_subset(&self, other: &HashSet<T, S>) -> bool {
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::HashSet;
///
/// let sub: HashSet<_> = [1, 2].iter().cloned().collect();
......
此差异已折叠。
......@@ -96,14 +96,16 @@ pub struct WalkDir {
/// Options and flags which can be used to configure how a file is opened.
///
/// This builder exposes the ability to configure how a `File` is opened and what operations are
/// permitted on the open file. The `File::open` and `File::create` methods are aliases for
/// commonly used options using this builder.
/// This builder exposes the ability to configure how a `File` is opened and
/// what operations are permitted on the open file. The `File::open` and
/// `File::create` methods are aliases for commonly used options using this
/// builder.
///
/// Generally speaking, when using `OpenOptions`, you'll first call `new()`, then chain calls to
/// methods to set each option, then call `open()`, passing the path of the file you're trying to
/// open. This will give you a [`io::Result`][result] with a [`File`][file] inside that you can
/// further operate on.
/// Generally speaking, when using `OpenOptions`, you'll first call `new()`,
/// then chain calls to methods to set each option, then call `open()`, passing
/// the path of the file you're trying to open. This will give you a
/// [`io::Result`][result] with a [`File`][file] inside that you can further
/// operate on.
///
/// [result]: ../io/type.Result.html
/// [file]: struct.File.html
......@@ -113,16 +115,15 @@ pub struct WalkDir {
/// Opening a file to read:
///
/// ```no_run
/// use std::fs;
/// use std::fs::OpenOptions;
///
/// let file = OpenOptions::new().read(true).open("foo.txt");
/// ```
///
/// Opening a file for both reading and writing, as well as creating it if it doesn't exist:
/// Opening a file for both reading and writing, as well as creating it if it
/// doesn't exist:
///
/// ```
/// use std::fs;
/// use std::fs::OpenOptions;
///
/// let file = OpenOptions::new()
......@@ -771,7 +772,9 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
/// ```no_run
/// use std::fs;
///
/// fs::copy("foo.txt", "bar.txt");
/// # fn foo() -> std::io::Result<()> {
/// try!(fs::copy("foo.txt", "bar.txt"));
/// # Ok(()) }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
......
......@@ -14,6 +14,7 @@
//! by adding a glob import to the top of I/O heavy modules:
//!
//! ```
//! # #![allow(unused_imports)]
//! use std::io::prelude::*;
//! ```
//!
......
......@@ -103,7 +103,8 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![doc(test(no_crate_inject))]
#![doc(test(no_crate_inject, attr(deny(warnings))))]
#![doc(test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
#![feature(alloc)]
#![feature(box_syntax)]
......
......@@ -281,7 +281,6 @@ fn hash<H: hash::Hasher>(&self, s: &mut H) {
/// Some examples:
///
/// ```no_run
/// # #![feature(net)]
/// use std::net::{SocketAddrV4, TcpStream, UdpSocket, TcpListener, Ipv4Addr};
///
/// fn main() {
......@@ -302,7 +301,7 @@ fn hash<H: hash::Hasher>(&self, s: &mut H) {
/// let tcp_l = TcpListener::bind("localhost:12345");
///
/// let mut udp_s = UdpSocket::bind(("127.0.0.1", port)).unwrap();
/// udp_s.send_to(&[7], (ip, 23451));
/// udp_s.send_to(&[7], (ip, 23451)).unwrap();
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
......
......@@ -27,7 +27,6 @@
/// # Examples
///
/// ```no_run
/// # #![feature(net)]
/// use std::io::prelude::*;
/// use std::net::TcpStream;
///
......@@ -47,7 +46,6 @@
/// # Examples
///
/// ```no_run
/// # #![feature(net)]
/// use std::net::{TcpListener, TcpStream};
/// use std::thread;
///
......
......@@ -27,7 +27,6 @@
/// # Examples
///
/// ```no_run
/// # #![feature(net)]
/// use std::net::UdpSocket;
///
/// # fn foo() -> std::io::Result<()> {
......
......@@ -422,7 +422,6 @@ pub fn is_finite(self) -> bool { num::Float::is_finite(self) }
/// [subnormal][subnormal], or `NaN`.
///
/// ```
/// # #![feature(std_misc)]
/// use std::f32;
///
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
......@@ -856,7 +855,7 @@ pub fn log10(self) -> f32 { num::Float::log10(self) }
/// Convert radians to degrees.
///
/// ```
/// # #![feature(std_misc, core)]
/// # #![feature(std_misc)]
/// use std::f32::{self, consts};
///
/// let angle = consts::PI;
......@@ -987,7 +986,6 @@ pub fn min(self, other: f32) -> f32 {
/// * Else: `self - other`
///
/// ```
/// # #![feature(std_misc)]
/// use std::f32;
///
/// let x = 3.0f32;
......@@ -1008,7 +1006,6 @@ pub fn abs_sub(self, other: f32) -> f32 {
/// Take the cubic root of a number.
///
/// ```
/// # #![feature(std_misc)]
/// use std::f32;
///
/// let x = 8.0f32;
......@@ -1210,8 +1207,6 @@ pub fn sin_cos(self) -> (f32, f32) {
/// number is close to zero.
///
/// ```
/// use std::f64;
///
/// let x = 7.0f64;
///
/// // e^(ln(7)) - 1
......
......@@ -280,7 +280,6 @@ pub trait Float
/// [subnormal][subnormal], or `NaN`.
///
/// ```
/// # #![feature(std_misc)]
/// use std::num::Float;
/// use std::f32;
///
......@@ -307,7 +306,6 @@ pub trait Float
/// predicate instead.
///
/// ```
/// # #![feature(core)]
/// use std::num::{Float, FpCategory};
/// use std::f32;
///
......@@ -417,7 +415,6 @@ pub trait Float
/// number is `Float::nan()`.
///
/// ```
/// # #![feature(std_misc)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -441,7 +438,6 @@ pub trait Float
/// - `Float::nan()` if the number is `Float::nan()`
///
/// ```
/// # #![feature(std_misc)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -686,7 +682,6 @@ pub trait Float
/// Convert radians to degrees.
///
/// ```
/// # #![feature(std_misc, core)]
/// use std::num::Float;
/// use std::f64::consts;
///
......@@ -701,7 +696,7 @@ pub trait Float
/// Convert degrees to radians.
///
/// ```
/// # #![feature(std_misc, core)]
/// # #![feature(std_misc)]
/// use std::num::Float;
/// use std::f64::consts;
///
......@@ -849,7 +844,6 @@ pub trait Float
/// Computes the sine of a number (in radians).
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -864,7 +858,6 @@ pub trait Float
/// Computes the cosine of a number (in radians).
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -879,7 +872,6 @@ pub trait Float
/// Computes the tangent of a number (in radians).
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -895,7 +887,6 @@ pub trait Float
/// [-1, 1].
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -913,7 +904,6 @@ pub trait Float
/// [-1, 1].
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -949,7 +939,6 @@ pub trait Float
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -975,7 +964,6 @@ pub trait Float
/// `(sin(x), cos(x))`.
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -1011,7 +999,6 @@ pub trait Float
/// the operations were performed separately.
///
/// ```
/// # #![feature(std_misc, core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -1028,7 +1015,6 @@ pub trait Float
/// Hyperbolic sine function.
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -1047,7 +1033,6 @@ pub trait Float
/// Hyperbolic cosine function.
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -1066,7 +1051,6 @@ pub trait Float
/// Hyperbolic tangent function.
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......@@ -1113,7 +1097,6 @@ pub trait Float
/// Inverse hyperbolic tangent function.
///
/// ```
/// # #![feature(core)]
/// use std::num::Float;
/// use std::f64;
///
......
......@@ -48,7 +48,7 @@
//! * Read lines from stdin
//!
//! ```rust
//! # #![feature(old_io, old_path)]
//! # #![feature(old_io)]
//! use std::old_io as io;
//! use std::old_io::*;
//!
......
......@@ -414,7 +414,7 @@ fn from_str(s: &str) -> Result<SocketAddr, ParseError> {
/// Some examples:
///
/// ```rust,no_run
/// # #![feature(old_io, core, convert)]
/// # #![feature(old_io)]
/// # #![allow(unused_must_use)]
///
/// use std::old_io::{TcpStream, TcpListener};
......
......@@ -191,7 +191,7 @@ impl UnixListener {
/// let server = Path::new("/path/to/my/socket");
/// let stream = UnixListener::bind(&server);
/// for mut client in stream.listen().incoming() {
/// client.write(&[1, 2, 3, 4]);
/// let _ = client.write(&[1, 2, 3, 4]);
/// }
/// # }
/// ```
......
......@@ -367,7 +367,7 @@ pub fn spawn(&self) -> IoResult<Process> {
/// # Examples
///
/// ```
/// # #![feature(old_io, core, convert)]
/// # #![feature(old_io)]
/// use std::old_io::Command;
///
/// let output = match Command::new("cat").arg("foot.txt").output() {
......
......@@ -144,12 +144,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
///
/// # Examples
///
/// ```
/// ```no_run
/// # #![feature(old_path)]
/// use std::old_path::{Path, GenericPath};
/// # foo();
/// # #[cfg(windows)] fn foo() {}
/// # #[cfg(unix)] fn foo() {
/// # fn main() {
/// use std::old_path::Path;
/// let path = Path::new("foo/bar");
/// # }
/// ```
......@@ -170,12 +168,10 @@ fn new<T: BytesContainer>(path: T) -> Self {
///
/// # Examples
///
/// ```
/// ```no_run
/// # #![feature(old_path)]
/// use std::old_path::{Path, GenericPath};
/// # foo();
/// # #[cfg(windows)] fn foo() {}
/// # #[cfg(unix)] fn foo() {
/// # fn main() {
/// use std::old_path::Path;
/// let x: &[u8] = b"foo\0";
/// assert!(Path::new_opt(x).is_none());
/// # }
......
......@@ -38,8 +38,6 @@
/// # Examples
///
/// ```should_panic
/// # #![feature(process)]
///
/// use std::process::Command;
///
/// let output = Command::new("/bin/cat").arg("file.txt").output().unwrap_or_else(|e| {
......@@ -267,10 +265,8 @@ pub fn spawn(&mut self) -> io::Result<Child> {
/// # Examples
///
/// ```
/// # #![feature(process)]
/// use std::process::Command;
///
/// let output = Command::new("cat").arg("foot.txt").output().unwrap_or_else(|e| {
/// let output = Command::new("cat").arg("foo.txt").output().unwrap_or_else(|e| {
/// panic!("failed to execute process: {}", e)
/// });
///
......@@ -291,7 +287,6 @@ pub fn output(&mut self) -> io::Result<Output> {
/// # Examples
///
/// ```
/// # #![feature(process)]
/// use std::process::Command;
///
/// let status = Command::new("ls").status().unwrap_or_else(|e| {
......
......@@ -99,6 +99,7 @@
//! `println!` and `panic!` for the child thread:
//!
//! ```rust
//! # #![allow(unused_must_use)]
//! use std::thread;
//!
//! thread::Builder::new().name("child1".to_string()).spawn(move || {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册