Skip to content

Commit ba40231

Browse files
committed
std: Deny most warnings in doctests
Allow a few specific ones but otherwise this helps ensure that our examples are squeaky clean! Closes #18199
1 parent 179719d commit ba40231

File tree

18 files changed

+212
-225
lines changed

18 files changed

+212
-225
lines changed

src/libcore/macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ macro_rules! writeln {
229229
/// Iterators:
230230
///
231231
/// ```
232-
/// # #![feature(core)]
233232
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
234233
/// for i in 0.. {
235234
/// if 3*i < i { panic!("u32 overflow"); }

src/libstd/collections/hash/set.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ impl<T, S> HashSet<T, S>
304304
/// # Examples
305305
///
306306
/// ```
307-
/// # #![feature(core)]
308307
/// use std::collections::HashSet;
309308
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
310309
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -335,7 +334,6 @@ impl<T, S> HashSet<T, S>
335334
/// # Examples
336335
///
337336
/// ```
338-
/// # #![feature(core)]
339337
/// use std::collections::HashSet;
340338
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
341339
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -362,7 +360,6 @@ impl<T, S> HashSet<T, S>
362360
/// # Examples
363361
///
364362
/// ```
365-
/// # #![feature(core)]
366363
/// use std::collections::HashSet;
367364
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
368365
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -388,7 +385,6 @@ impl<T, S> HashSet<T, S>
388385
/// # Examples
389386
///
390387
/// ```
391-
/// # #![feature(core)]
392388
/// use std::collections::HashSet;
393389
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
394390
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -471,7 +467,6 @@ impl<T, S> HashSet<T, S>
471467
/// # Examples
472468
///
473469
/// ```
474-
/// # #![feature(core)]
475470
/// use std::collections::HashSet;
476471
///
477472
/// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -491,7 +486,6 @@ impl<T, S> HashSet<T, S>
491486
/// # Examples
492487
///
493488
/// ```
494-
/// # #![feature(core)]
495489
/// use std::collections::HashSet;
496490
///
497491
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -513,7 +507,6 @@ impl<T, S> HashSet<T, S>
513507
/// # Examples
514508
///
515509
/// ```
516-
/// # #![feature(core)]
517510
/// use std::collections::HashSet;
518511
///
519512
/// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -535,7 +528,6 @@ impl<T, S> HashSet<T, S>
535528
/// # Examples
536529
///
537530
/// ```
538-
/// # #![feature(core)]
539531
/// use std::collections::HashSet;
540532
///
541533
/// let sub: HashSet<_> = [1, 2].iter().cloned().collect();

src/libstd/collections/mod.rs

Lines changed: 180 additions & 155 deletions
Large diffs are not rendered by default.

src/libstd/fs.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ pub struct WalkDir {
9696

9797
/// Options and flags which can be used to configure how a file is opened.
9898
///
99-
/// This builder exposes the ability to configure how a `File` is opened and what operations are
100-
/// permitted on the open file. The `File::open` and `File::create` methods are aliases for
101-
/// commonly used options using this builder.
99+
/// This builder exposes the ability to configure how a `File` is opened and
100+
/// what operations are permitted on the open file. The `File::open` and
101+
/// `File::create` methods are aliases for commonly used options using this
102+
/// builder.
102103
///
103-
/// Generally speaking, when using `OpenOptions`, you'll first call `new()`, then chain calls to
104-
/// methods to set each option, then call `open()`, passing the path of the file you're trying to
105-
/// open. This will give you a [`io::Result`][result] with a [`File`][file] inside that you can
106-
/// further operate on.
104+
/// Generally speaking, when using `OpenOptions`, you'll first call `new()`,
105+
/// then chain calls to methods to set each option, then call `open()`, passing
106+
/// the path of the file you're trying to open. This will give you a
107+
/// [`io::Result`][result] with a [`File`][file] inside that you can further
108+
/// operate on.
107109
///
108110
/// [result]: ../io/type.Result.html
109111
/// [file]: struct.File.html
@@ -113,16 +115,15 @@ pub struct WalkDir {
113115
/// Opening a file to read:
114116
///
115117
/// ```no_run
116-
/// use std::fs;
117118
/// use std::fs::OpenOptions;
118119
///
119120
/// let file = OpenOptions::new().read(true).open("foo.txt");
120121
/// ```
121122
///
122-
/// Opening a file for both reading and writing, as well as creating it if it doesn't exist:
123+
/// Opening a file for both reading and writing, as well as creating it if it
124+
/// doesn't exist:
123125
///
124126
/// ```
125-
/// use std::fs;
126127
/// use std::fs::OpenOptions;
127128
///
128129
/// let file = OpenOptions::new()
@@ -771,7 +772,9 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
771772
/// ```no_run
772773
/// use std::fs;
773774
///
774-
/// fs::copy("foo.txt", "bar.txt");
775+
/// # fn foo() -> std::io::Result<()> {
776+
/// try!(fs::copy("foo.txt", "bar.txt"));
777+
/// # Ok(()) }
775778
/// ```
776779
#[stable(feature = "rust1", since = "1.0.0")]
777780
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {

src/libstd/io/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! by adding a glob import to the top of I/O heavy modules:
1515
//!
1616
//! ```
17+
//! # #![allow(unused_imports)]
1718
//! use std::io::prelude::*;
1819
//! ```
1920
//!

src/libstd/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
104104
html_root_url = "http://doc.rust-lang.org/nightly/",
105105
html_playground_url = "http://play.rust-lang.org/")]
106-
#![doc(test(no_crate_inject))]
106+
#![doc(test(no_crate_inject, attr(deny(warnings))))]
107+
#![doc(test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
107108

108109
#![feature(alloc)]
109110
#![feature(box_syntax)]

src/libstd/net/addr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ impl hash::Hash for SocketAddrV6 {
281281
/// Some examples:
282282
///
283283
/// ```no_run
284-
/// # #![feature(net)]
285284
/// use std::net::{SocketAddrV4, TcpStream, UdpSocket, TcpListener, Ipv4Addr};
286285
///
287286
/// fn main() {
@@ -302,7 +301,7 @@ impl hash::Hash for SocketAddrV6 {
302301
/// let tcp_l = TcpListener::bind("localhost:12345");
303302
///
304303
/// let mut udp_s = UdpSocket::bind(("127.0.0.1", port)).unwrap();
305-
/// udp_s.send_to(&[7], (ip, 23451));
304+
/// udp_s.send_to(&[7], (ip, 23451)).unwrap();
306305
/// }
307306
/// ```
308307
#[stable(feature = "rust1", since = "1.0.0")]

src/libstd/net/tcp.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use sys_common::{AsInner, FromInner};
2727
/// # Examples
2828
///
2929
/// ```no_run
30-
/// # #![feature(net)]
3130
/// use std::io::prelude::*;
3231
/// use std::net::TcpStream;
3332
///
@@ -47,7 +46,6 @@ pub struct TcpStream(net_imp::TcpStream);
4746
/// # Examples
4847
///
4948
/// ```no_run
50-
/// # #![feature(net)]
5149
/// use std::net::{TcpListener, TcpStream};
5250
/// use std::thread;
5351
///

src/libstd/net/udp.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use sys_common::{AsInner, FromInner};
2727
/// # Examples
2828
///
2929
/// ```no_run
30-
/// # #![feature(net)]
3130
/// use std::net::UdpSocket;
3231
///
3332
/// # fn foo() -> std::io::Result<()> {

src/libstd/num/f32.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ impl f32 {
422422
/// [subnormal][subnormal], or `NaN`.
423423
///
424424
/// ```
425-
/// # #![feature(std_misc)]
426425
/// use std::f32;
427426
///
428427
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
@@ -856,7 +855,7 @@ impl f32 {
856855
/// Convert radians to degrees.
857856
///
858857
/// ```
859-
/// # #![feature(std_misc, core)]
858+
/// # #![feature(std_misc)]
860859
/// use std::f32::{self, consts};
861860
///
862861
/// let angle = consts::PI;
@@ -987,7 +986,6 @@ impl f32 {
987986
/// * Else: `self - other`
988987
///
989988
/// ```
990-
/// # #![feature(std_misc)]
991989
/// use std::f32;
992990
///
993991
/// let x = 3.0f32;
@@ -1008,7 +1006,6 @@ impl f32 {
10081006
/// Take the cubic root of a number.
10091007
///
10101008
/// ```
1011-
/// # #![feature(std_misc)]
10121009
/// use std::f32;
10131010
///
10141011
/// let x = 8.0f32;
@@ -1210,8 +1207,6 @@ impl f32 {
12101207
/// number is close to zero.
12111208
///
12121209
/// ```
1213-
/// use std::f64;
1214-
///
12151210
/// let x = 7.0f64;
12161211
///
12171212
/// // e^(ln(7)) - 1

src/libstd/num/mod.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ pub trait Float
280280
/// [subnormal][subnormal], or `NaN`.
281281
///
282282
/// ```
283-
/// # #![feature(std_misc)]
284283
/// use std::num::Float;
285284
/// use std::f32;
286285
///
@@ -307,7 +306,6 @@ pub trait Float
307306
/// predicate instead.
308307
///
309308
/// ```
310-
/// # #![feature(core)]
311309
/// use std::num::{Float, FpCategory};
312310
/// use std::f32;
313311
///
@@ -417,7 +415,6 @@ pub trait Float
417415
/// number is `Float::nan()`.
418416
///
419417
/// ```
420-
/// # #![feature(std_misc)]
421418
/// use std::num::Float;
422419
/// use std::f64;
423420
///
@@ -441,7 +438,6 @@ pub trait Float
441438
/// - `Float::nan()` if the number is `Float::nan()`
442439
///
443440
/// ```
444-
/// # #![feature(std_misc)]
445441
/// use std::num::Float;
446442
/// use std::f64;
447443
///
@@ -686,7 +682,6 @@ pub trait Float
686682
/// Convert radians to degrees.
687683
///
688684
/// ```
689-
/// # #![feature(std_misc, core)]
690685
/// use std::num::Float;
691686
/// use std::f64::consts;
692687
///
@@ -701,7 +696,7 @@ pub trait Float
701696
/// Convert degrees to radians.
702697
///
703698
/// ```
704-
/// # #![feature(std_misc, core)]
699+
/// # #![feature(std_misc)]
705700
/// use std::num::Float;
706701
/// use std::f64::consts;
707702
///
@@ -849,7 +844,6 @@ pub trait Float
849844
/// Computes the sine of a number (in radians).
850845
///
851846
/// ```
852-
/// # #![feature(core)]
853847
/// use std::num::Float;
854848
/// use std::f64;
855849
///
@@ -864,7 +858,6 @@ pub trait Float
864858
/// Computes the cosine of a number (in radians).
865859
///
866860
/// ```
867-
/// # #![feature(core)]
868861
/// use std::num::Float;
869862
/// use std::f64;
870863
///
@@ -879,7 +872,6 @@ pub trait Float
879872
/// Computes the tangent of a number (in radians).
880873
///
881874
/// ```
882-
/// # #![feature(core)]
883875
/// use std::num::Float;
884876
/// use std::f64;
885877
///
@@ -895,7 +887,6 @@ pub trait Float
895887
/// [-1, 1].
896888
///
897889
/// ```
898-
/// # #![feature(core)]
899890
/// use std::num::Float;
900891
/// use std::f64;
901892
///
@@ -913,7 +904,6 @@ pub trait Float
913904
/// [-1, 1].
914905
///
915906
/// ```
916-
/// # #![feature(core)]
917907
/// use std::num::Float;
918908
/// use std::f64;
919909
///
@@ -949,7 +939,6 @@ pub trait Float
949939
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
950940
///
951941
/// ```
952-
/// # #![feature(core)]
953942
/// use std::num::Float;
954943
/// use std::f64;
955944
///
@@ -975,7 +964,6 @@ pub trait Float
975964
/// `(sin(x), cos(x))`.
976965
///
977966
/// ```
978-
/// # #![feature(core)]
979967
/// use std::num::Float;
980968
/// use std::f64;
981969
///
@@ -1011,7 +999,6 @@ pub trait Float
1011999
/// the operations were performed separately.
10121000
///
10131001
/// ```
1014-
/// # #![feature(std_misc, core)]
10151002
/// use std::num::Float;
10161003
/// use std::f64;
10171004
///
@@ -1028,7 +1015,6 @@ pub trait Float
10281015
/// Hyperbolic sine function.
10291016
///
10301017
/// ```
1031-
/// # #![feature(core)]
10321018
/// use std::num::Float;
10331019
/// use std::f64;
10341020
///
@@ -1047,7 +1033,6 @@ pub trait Float
10471033
/// Hyperbolic cosine function.
10481034
///
10491035
/// ```
1050-
/// # #![feature(core)]
10511036
/// use std::num::Float;
10521037
/// use std::f64;
10531038
///
@@ -1066,7 +1051,6 @@ pub trait Float
10661051
/// Hyperbolic tangent function.
10671052
///
10681053
/// ```
1069-
/// # #![feature(core)]
10701054
/// use std::num::Float;
10711055
/// use std::f64;
10721056
///
@@ -1113,7 +1097,6 @@ pub trait Float
11131097
/// Inverse hyperbolic tangent function.
11141098
///
11151099
/// ```
1116-
/// # #![feature(core)]
11171100
/// use std::num::Float;
11181101
/// use std::f64;
11191102
///

src/libstd/old_io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
//! * Read lines from stdin
4949
//!
5050
//! ```rust
51-
//! # #![feature(old_io, old_path)]
51+
//! # #![feature(old_io)]
5252
//! use std::old_io as io;
5353
//! use std::old_io::*;
5454
//!

src/libstd/old_io/net/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub struct ParseError;
414414
/// Some examples:
415415
///
416416
/// ```rust,no_run
417-
/// # #![feature(old_io, core, convert)]
417+
/// # #![feature(old_io)]
418418
/// # #![allow(unused_must_use)]
419419
///
420420
/// use std::old_io::{TcpStream, TcpListener};

src/libstd/old_io/net/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl UnixListener {
191191
/// let server = Path::new("/path/to/my/socket");
192192
/// let stream = UnixListener::bind(&server);
193193
/// for mut client in stream.listen().incoming() {
194-
/// client.write(&[1, 2, 3, 4]);
194+
/// let _ = client.write(&[1, 2, 3, 4]);
195195
/// }
196196
/// # }
197197
/// ```

0 commit comments

Comments
 (0)