Skip to content

Commit 82784cb

Browse files
committed
libcore: deny warnings in doctests
1 parent bbf964a commit 82784cb

File tree

14 files changed

+48
-10
lines changed

14 files changed

+48
-10
lines changed

src/libcore/cell.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
//! a trait method that was originally defined to take `&self`.
7777
//!
7878
//! ```
79+
//! # #![allow(dead_code)]
7980
//! use std::cell::RefCell;
8081
//!
8182
//! struct Graph {
@@ -125,6 +126,7 @@
125126
//! }
126127
//!
127128
//! struct RcBox<T> {
129+
//! # #[allow(dead_code)]
128130
//! value: T,
129131
//! refcount: Cell<usize>
130132
//! }
@@ -776,6 +778,7 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
776778
/// use std::cell::UnsafeCell;
777779
/// use std::marker::Sync;
778780
///
781+
/// # #[allow(dead_code)]
779782
/// struct NotThreadSafe<T> {
780783
/// value: UnsafeCell<T>,
781784
/// }

src/libcore/cmp.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ impl Ordering {
140140
/// This method can be used to reverse a comparison:
141141
///
142142
/// ```
143-
/// use std::cmp::Ordering;
144-
///
145143
/// let mut data: &mut [_] = &mut [2, 10, 5, 8];
146144
///
147145
/// // sort the array from largest to smallest.
@@ -263,8 +261,6 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
263261
/// # Examples
264262
///
265263
/// ```
266-
/// use std::cmp::Ordering;
267-
///
268264
/// let result = 1.0 < 2.0;
269265
/// assert_eq!(result, true);
270266
///

src/libcore/default.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! that define a set of options:
1616
//!
1717
//! ```
18+
//! # #[allow(dead_code)]
1819
//! struct SomeOptions {
1920
//! foo: i32,
2021
//! bar: f32,
@@ -24,6 +25,7 @@
2425
//! How can we define some default values? You can use `Default`:
2526
//!
2627
//! ```
28+
//! # #[allow(dead_code)]
2729
//! #[derive(Default)]
2830
//! struct SomeOptions {
2931
//! foo: i32,
@@ -40,6 +42,7 @@
4042
//! If you have your own type, you need to implement `Default` yourself:
4143
//!
4244
//! ```
45+
//! # #![allow(dead_code)]
4346
//! enum Kind {
4447
//! A,
4548
//! B,
@@ -66,6 +69,7 @@
6669
//! If you want to override a particular option, but still retain the other defaults:
6770
//!
6871
//! ```
72+
//! # #[allow(dead_code)]
6973
//! # #[derive(Default)]
7074
//! # struct SomeOptions {
7175
//! # foo: i32,
@@ -88,6 +92,7 @@ use marker::Sized;
8892
/// # Examples
8993
///
9094
/// ```
95+
/// # #[allow(dead_code)]
9196
/// #[derive(Default)]
9297
/// struct SomeOptions {
9398
/// foo: i32,
@@ -114,6 +119,7 @@ pub trait Default: Sized {
114119
/// Making your own:
115120
///
116121
/// ```
122+
/// # #[allow(dead_code)]
117123
/// enum Kind {
118124
/// A,
119125
/// B,

src/libcore/hash/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
//!
4646
//! struct Person {
4747
//! id: u32,
48+
//! # #[allow(dead_code)]
4849
//! name: String,
4950
//! phone: u64,
5051
//! }

src/libcore/intrinsics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ extern "rust-intrinsic" {
334334
/// use std::mem;
335335
/// use std::ptr;
336336
///
337+
/// # #[allow(dead_code)]
337338
/// fn swap<T>(x: &mut T, y: &mut T) {
338339
/// unsafe {
339340
/// // Give ourselves some scratch space to work with
@@ -372,6 +373,7 @@ extern "rust-intrinsic" {
372373
/// ```
373374
/// use std::ptr;
374375
///
376+
/// # #[allow(dead_code)]
375377
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
376378
/// let mut dst = Vec::with_capacity(elts);
377379
/// dst.set_len(elts);

src/libcore/iter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
//! method calls a closure on each element it iterates over:
242242
//!
243243
//! ```
244+
//! # #![allow(unused_must_use)]
244245
//! let v = vec![1, 2, 3, 4, 5];
245246
//! v.iter().map(|x| println!("{}", x));
246247
//! ```
@@ -419,7 +420,7 @@ pub trait Iterator {
419420
///
420421
/// ```
421422
/// // an infinite iterator has no upper bound
422-
/// let iter = (0..);
423+
/// let iter = 0..;
423424
///
424425
/// assert_eq!((0, None), iter.size_hint());
425426
/// ```
@@ -709,6 +710,7 @@ pub trait Iterator {
709710
/// If you're doing some sort of side effect, prefer [`for`] to `map()`:
710711
///
711712
/// ```
713+
/// # #![allow(unused_must_use)]
712714
/// // don't do this:
713715
/// (0..5).map(|x| println!("{}", x));
714716
///
@@ -2695,7 +2697,7 @@ impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I {
26952697
///
26962698
/// ```
26972699
/// // a finite range knows exactly how many times it will iterate
2698-
/// let five = (0..5);
2700+
/// let five = 0..5;
26992701
///
27002702
/// assert_eq!(5, five.len());
27012703
/// ```
@@ -2761,7 +2763,7 @@ pub trait ExactSizeIterator: Iterator {
27612763
///
27622764
/// ```
27632765
/// // a finite range knows exactly how many times it will iterate
2764-
/// let five = (0..5);
2766+
/// let five = 0..5;
27652767
///
27662768
/// assert_eq!(5, five.len());
27672769
/// ```

src/libcore/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
html_root_url = "https://doc.rust-lang.org/nightly/",
6161
html_playground_url = "https://play.rust-lang.org/",
6262
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
63-
#![doc(test(no_crate_inject))]
63+
#![doc(test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
6464

6565
#![no_core]
6666
#![allow(raw_pointer_derive)]

src/libcore/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ macro_rules! writeln {
247247
/// Match arms:
248248
///
249249
/// ```
250+
/// # #[allow(dead_code)]
250251
/// fn foo(x: Option<i32>) {
251252
/// match x {
252253
/// Some(n) if n >= 0 => println!("Some(Non-negative)"),
@@ -260,6 +261,7 @@ macro_rules! writeln {
260261
/// Iterators:
261262
///
262263
/// ```
264+
/// # #[allow(dead_code)]
263265
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
264266
/// for i in 0.. {
265267
/// if 3*i < i { panic!("u32 overflow"); }

src/libcore/marker.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl<T> !Send for *mut T { }
4242
/// `?Sized` can be used to remove this bound if it is not appropriate.
4343
///
4444
/// ```
45+
/// # #![allow(dead_code)]
4546
/// struct Foo<T>(T);
4647
/// struct Bar<T: ?Sized>(T);
4748
///
@@ -106,6 +107,7 @@ pub trait Unsize<T: ?Sized> {
106107
/// `struct` can be `Copy`:
107108
///
108109
/// ```
110+
/// # #[allow(dead_code)]
109111
/// struct Point {
110112
/// x: i32,
111113
/// y: i32,
@@ -115,6 +117,7 @@ pub trait Unsize<T: ?Sized> {
115117
/// A `struct` can be `Copy`, and `i32` is `Copy`, so therefore, `Point` is eligible to be `Copy`.
116118
///
117119
/// ```
120+
/// # #![allow(dead_code)]
118121
/// # struct Point;
119122
/// struct PointList {
120123
/// points: Vec<Point>,
@@ -303,6 +306,7 @@ macro_rules! impls{
303306
/// ```
304307
/// use std::marker::PhantomData;
305308
///
309+
/// # #[allow(dead_code)]
306310
/// struct Slice<'a, T:'a> {
307311
/// start: *const T,
308312
/// end: *const T,
@@ -323,6 +327,7 @@ macro_rules! impls{
323327
/// mismatches by enforcing types in the method implementations:
324328
///
325329
/// ```
330+
/// # #![allow(dead_code)]
326331
/// # trait ResType { fn foo(&self); }
327332
/// # struct ParamType;
328333
/// # mod foreign_lib {
@@ -393,6 +398,8 @@ mod impls {
393398
/// #![feature(reflect_marker)]
394399
/// use std::marker::Reflect;
395400
/// use std::any::Any;
401+
///
402+
/// # #[allow(dead_code)]
396403
/// fn foo<T:Reflect+'static>(x: &T) {
397404
/// let any: &Any = x;
398405
/// if any.is::<u32>() { println!("u32"); }

src/libcore/mem.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub use intrinsics::transmute;
9292
/// use std::mem;
9393
/// use std::ptr;
9494
///
95+
/// # #[allow(dead_code)]
9596
/// fn swap<T>(x: &mut T, y: &mut T) {
9697
/// unsafe {
9798
/// // Give ourselves some scratch space to work with
@@ -151,6 +152,7 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
151152
/// # Examples
152153
///
153154
/// ```
155+
/// # #![allow(deprecated)]
154156
/// use std::mem;
155157
///
156158
/// assert_eq!(4, mem::min_align_of::<i32>());
@@ -167,6 +169,7 @@ pub fn min_align_of<T>() -> usize {
167169
/// # Examples
168170
///
169171
/// ```
172+
/// # #![allow(deprecated)]
170173
/// use std::mem;
171174
///
172175
/// assert_eq!(4, mem::min_align_of_val(&5i32));
@@ -414,6 +417,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
414417
/// `self`, allowing it to be returned:
415418
///
416419
/// ```
420+
/// # #![allow(dead_code)]
417421
/// use std::mem;
418422
/// # struct Buffer<T> { buf: Vec<T> }
419423
/// impl<T> Buffer<T> {

src/libcore/ops.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
947947
/// }
948948
/// }
949949
///
950+
/// # #[allow(unused_assignments)]
950951
/// fn main() {
951952
/// let mut foo = Foo;
952953
/// foo += Foo;
@@ -996,6 +997,7 @@ add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
996997
/// }
997998
/// }
998999
///
1000+
/// # #[allow(unused_assignments)]
9991001
/// fn main() {
10001002
/// let mut foo = Foo;
10011003
/// foo -= Foo;
@@ -1045,6 +1047,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
10451047
/// }
10461048
/// }
10471049
///
1050+
/// # #[allow(unused_assignments)]
10481051
/// fn main() {
10491052
/// let mut foo = Foo;
10501053
/// foo *= Foo;
@@ -1094,6 +1097,7 @@ mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
10941097
/// }
10951098
/// }
10961099
///
1100+
/// # #[allow(unused_assignments)]
10971101
/// fn main() {
10981102
/// let mut foo = Foo;
10991103
/// foo /= Foo;
@@ -1143,6 +1147,7 @@ div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
11431147
/// }
11441148
/// }
11451149
///
1150+
/// # #[allow(unused_assignments)]
11461151
/// fn main() {
11471152
/// let mut foo = Foo;
11481153
/// foo %= Foo;
@@ -1192,6 +1197,7 @@ rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
11921197
/// }
11931198
/// }
11941199
///
1200+
/// # #[allow(unused_assignments)]
11951201
/// fn main() {
11961202
/// let mut foo = Foo;
11971203
/// foo &= Foo;
@@ -1241,6 +1247,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
12411247
/// }
12421248
/// }
12431249
///
1250+
/// # #[allow(unused_assignments)]
12441251
/// fn main() {
12451252
/// let mut foo = Foo;
12461253
/// foo |= Foo;
@@ -1290,6 +1297,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
12901297
/// }
12911298
/// }
12921299
///
1300+
/// # #[allow(unused_assignments)]
12931301
/// fn main() {
12941302
/// let mut foo = Foo;
12951303
/// foo ^= Foo;
@@ -1339,6 +1347,7 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
13391347
/// }
13401348
/// }
13411349
///
1350+
/// # #[allow(unused_assignments)]
13421351
/// fn main() {
13431352
/// let mut foo = Foo;
13441353
/// foo <<= Foo;
@@ -1407,6 +1416,7 @@ shl_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
14071416
/// }
14081417
/// }
14091418
///
1419+
/// # #[allow(unused_assignments)]
14101420
/// fn main() {
14111421
/// let mut foo = Foo;
14121422
/// foo >>= Foo;

src/libcore/option.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl<T> Option<T> {
275275
///
276276
/// ```
277277
/// #![feature(as_slice)]
278+
/// # #![allow(deprecated)]
278279
///
279280
/// let mut x = Some("Diamonds");
280281
/// {

src/libcore/result.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//! and containing an error value.
1717
//!
1818
//! ```
19+
//! # #[allow(dead_code)]
1920
//! enum Result<T, E> {
2021
//! Ok(T),
2122
//! Err(E)
@@ -104,6 +105,7 @@
104105
//! something like this:
105106
//!
106107
//! ```no_run
108+
//! # #![allow(unused_must_use)] // \o/
107109
//! use std::fs::File;
108110
//! use std::io::prelude::*;
109111
//!
@@ -143,6 +145,7 @@
143145
//! # use std::fs::File;
144146
//! # use std::io::prelude::*;
145147
//! # use std::io;
148+
//! # #[allow(dead_code)]
146149
//! fn write_message() -> io::Result<()> {
147150
//! let mut file = try!(File::create("valuable_data.txt"));
148151
//! try!(file.write_all(b"important message"));
@@ -160,6 +163,7 @@
160163
//! It replaces this:
161164
//!
162165
//! ```
166+
//! # #![allow(dead_code)]
163167
//! use std::fs::File;
164168
//! use std::io::prelude::*;
165169
//! use std::io;
@@ -189,6 +193,7 @@
189193
//! With this:
190194
//!
191195
//! ```
196+
//! # #![allow(dead_code)]
192197
//! use std::fs::File;
193198
//! use std::io::prelude::*;
194199
//! use std::io;
@@ -422,6 +427,7 @@ impl<T, E> Result<T, E> {
422427
///
423428
/// ```
424429
/// #![feature(as_slice)]
430+
/// # #![allow(deprecated)]
425431
///
426432
/// let mut x: Result<&str, u32> = Ok("Gold");
427433
/// {

0 commit comments

Comments
 (0)