From fdb28267387593974f4157dcc9558c8757805230 Mon Sep 17 00:00:00 2001 From: Eric Findlay Date: Wed, 28 Oct 2015 10:39:22 +0900 Subject: [PATCH 01/27] Added try! example to documentation.md --- src/doc/trpl/documentation.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index e101d4bc0d4dc..e130109e35492 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -373,6 +373,36 @@ we can add the `#[macro_use]` attribute. Second, we’ll need to add our own `main()` as well. Finally, a judicious use of `#` to comment out those two things, so they don’t show up in the output. +Another case where the use of `#` is handy is when you want to ignore +error handling. Lets say you want the following, + +```rust +/// use std::io; +/// let mut input = String::new(); +/// try!(io::stdin().read_line(&mut input)); +``` + +The problem is that `try!` returns a `Result` and test functions +don't return anything so this will give a mismatched types error. + +```rust +/// A doc test using try! +/// +/// ``` +/// use std::io; +/// # fn f() -> io::Result<()> { +/// let mut input = String::new(); +/// try!(io::stdin().read_line(&mut input)); +/// # Ok(()) +/// # } +/// # f(); +/// ``` +``` + +You can get around this by wrapping the code in a function. This catches +and swallows the `Result` when running tests on the docs. This +pattern appears regularly in the standard library. + ### Running documentation tests To run the tests, either: From b2c3745229e8a0472f2a4ebede7496572e6b6d0e Mon Sep 17 00:00:00 2001 From: Eric Findlay Date: Thu, 29 Oct 2015 09:43:54 +0900 Subject: [PATCH 02/27] Added "ignore" to rustdoc example, r=steveklabnik Fixes #29234 --- src/doc/trpl/documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index e130109e35492..191a51dffdbfc 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -376,7 +376,7 @@ things, so they don’t show up in the output. Another case where the use of `#` is handy is when you want to ignore error handling. Lets say you want the following, -```rust +```rust,ignore /// use std::io; /// let mut input = String::new(); /// try!(io::stdin().read_line(&mut input)); From f11d4a9ca52d583912069dcb0a68981c2596ef2a Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 14:02:48 +0000 Subject: [PATCH 03/27] liballoc: deny warnings in doctests --- src/liballoc/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 899e7de4ed59f..4113f67e617d1 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -70,7 +70,7 @@ html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", - test(no_crate_inject))] + test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] #![cfg_attr(not(stage0), needs_allocator)] From 3eb395a3f0c51fef9c1e0cbabf1d2aee660609a3 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 14:03:22 +0000 Subject: [PATCH 04/27] libarena: deny warnings in doctests --- mk/tests.mk | 2 +- src/libarena/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index d004558d1bf3f..8fd4d80199441 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,7 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) +TEST_DOC_CRATES = $(DOC_CRATES) arena TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 5bc1c44e1b1fb..2234d3608f3f3 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -28,7 +28,8 @@ #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] + html_root_url = "https://doc.rust-lang.org/nightly/", + test(no_crate_inject, attr(deny(warnings))))] #![feature(alloc)] #![feature(box_syntax)] From 81b1790b984ebcddff4508d68edbc66e10dbf7f3 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 14:49:33 +0000 Subject: [PATCH 05/27] libcollections: deny warnings in doctests --- src/libcollections/binary_heap.rs | 1 + src/libcollections/borrow.rs | 1 + src/libcollections/btree/set.rs | 1 + src/libcollections/fmt.rs | 3 ++- src/libcollections/lib.rs | 2 +- src/libcollections/slice.rs | 1 + src/libcollections/str.rs | 10 ++++------ src/libcollections/string.rs | 15 +++++++++++++++ src/libcollections/vec.rs | 1 + 9 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 30fc22e400a81..72547a9a5d2ee 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -233,6 +233,7 @@ impl BinaryHeap { /// /// ``` /// #![feature(binary_heap_extras)] + /// # #![allow(deprecated)] /// /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from_vec(vec![9, 1, 2, 7, 3, 2]); diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs index bd1864b28cdd3..9b8f8c8f5bb84 100644 --- a/src/libcollections/borrow.rs +++ b/src/libcollections/borrow.rs @@ -72,6 +72,7 @@ impl ToOwned for T where T: Clone { /// ``` /// use std::borrow::Cow; /// +/// # #[allow(dead_code)] /// fn abs_all(input: &mut Cow<[i32]>) { /// for i in 0..input.len() { /// let v = input[i]; diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 3ca0aa377c102..ee23a6c846956 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -89,6 +89,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![allow(unused_mut)] /// use std::collections::BTreeSet; /// /// let mut set: BTreeSet = BTreeSet::new(); diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index a31ad6c109362..990575ebbb336 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -150,6 +150,7 @@ //! implement a method of the signature: //! //! ``` +//! # #![allow(dead_code)] //! # use std::fmt; //! # struct Foo; // our custom type //! # impl fmt::Display for Foo { @@ -174,7 +175,6 @@ //! like: //! //! ``` -//! #![feature(fmt_flags)] //! use std::fmt; //! //! #[derive(Debug)] @@ -288,6 +288,7 @@ //! off, some example usage is: //! //! ``` +//! # #![allow(unused_must_use)] //! use std::fmt; //! use std::io::{self, Write}; //! diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 670c32776df7b..54b98c6e17992 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -27,7 +27,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/", - test(no_crate_inject))] + test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![allow(trivial_casts)] #![cfg_attr(test, allow(deprecated))] // rand diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ea4830fc3e6ce..3e681db92481e 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -851,6 +851,7 @@ pub trait SliceConcatExt { /// # Examples /// /// ``` + /// # #![allow(deprecated)] /// assert_eq!(["hello", "world"].connect(" "), "hello world"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 21406354d81c3..112c7d5d2f63e 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -299,7 +299,7 @@ impl str { /// done by `.chars()` or `.char_indices()`. /// /// ``` - /// #![feature(str_char, core)] + /// #![feature(str_char)] /// /// use std::str::CharRange; /// @@ -359,7 +359,7 @@ impl str { /// done by `.chars().rev()` or `.char_indices()`. /// /// ``` - /// #![feature(str_char, core)] + /// #![feature(str_char)] /// /// use std::str::CharRange; /// @@ -635,6 +635,7 @@ impl str { /// # Examples /// /// ``` + /// # #![allow(deprecated)] /// let four_lines = "foo\r\nbar\n\r\nbaz"; /// let v: Vec<&str> = four_lines.lines_any().collect(); /// @@ -644,6 +645,7 @@ impl str { /// Leaving off the trailing character: /// /// ``` + /// # #![allow(deprecated)] /// let four_lines = "foo\r\nbar\n\r\nbaz\n"; /// let v: Vec<&str> = four_lines.lines_any().collect(); /// @@ -1180,8 +1182,6 @@ impl str { /// # Examples /// /// ``` - /// #![feature(str_match_indices)] - /// /// let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); /// assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); /// @@ -1217,8 +1217,6 @@ impl str { /// # Examples /// /// ``` - /// #![feature(str_match_indices)] - /// /// let v: Vec<_> = "abcXXXabcYYYabc".rmatch_indices("abc").collect(); /// assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]); /// diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8d07e2b2018ad..0e4c73f62a64f 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -55,6 +55,7 @@ impl String { /// # Examples /// /// ``` + /// # #![allow(unused_mut)] /// let mut s = String::new(); /// ``` #[inline] @@ -73,6 +74,20 @@ impl String { /// /// ``` /// let mut s = String::with_capacity(10); + /// + /// // The String contains no chars, even though it has capacity for more + /// assert_eq!(s.len(), 0); + /// + /// // These are all done without reallocating... + /// let cap = s.capacity(); + /// for i in 0..10 { + /// s.push('a'); + /// } + /// + /// assert_eq!(s.capacity(), cap); + /// + /// // ...but this may make the vector reallocate + /// s.push('a'); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index a22e66583c4a9..571df8e2c0b42 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -242,6 +242,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![allow(unused_mut)] /// let mut vec: Vec = Vec::new(); /// ``` #[inline] From d9c01141d95c87d89ee23f752f7eda6ed01da405 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:27:03 +0000 Subject: [PATCH 06/27] libcore: deny warnings in doctests --- src/libcore/cell.rs | 3 +++ src/libcore/cmp.rs | 4 ---- src/libcore/default.rs | 6 ++++++ src/libcore/hash/mod.rs | 1 + src/libcore/intrinsics.rs | 2 ++ src/libcore/iter.rs | 8 +++++--- src/libcore/lib.rs | 2 +- src/libcore/macros.rs | 2 ++ src/libcore/marker.rs | 7 +++++++ src/libcore/mem.rs | 4 ++++ src/libcore/ops.rs | 10 ++++++++++ src/libcore/option.rs | 1 + src/libcore/result.rs | 6 ++++++ src/libcore/str/mod.rs | 2 -- 14 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1dc989018ad26..3911519c4790d 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -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 { +//! # #[allow(dead_code)] //! value: T, //! refcount: Cell //! } @@ -778,6 +780,7 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> { /// use std::cell::UnsafeCell; /// use std::marker::Sync; /// +/// # #[allow(dead_code)] /// struct NotThreadSafe { /// value: UnsafeCell, /// } diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index fa1f4727bc078..831476ed83022 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -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. @@ -265,8 +263,6 @@ pub trait PartialOrd: PartialEq { /// # Examples /// /// ``` - /// use std::cmp::Ordering; - /// /// let result = 1.0 < 2.0; /// assert_eq!(result, true); /// diff --git a/src/libcore/default.rs b/src/libcore/default.rs index f7fda3d04fd61..79b7050704cd7 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -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 @@ use marker::Sized; /// # 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, diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 4e038f455e1be..0899dc2884819 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -45,6 +45,7 @@ //! //! struct Person { //! id: u32, +//! # #[allow(dead_code)] //! name: String, //! phone: u64, //! } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index ea4792bb495f6..a094bcd0192d2 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -334,6 +334,7 @@ extern "rust-intrinsic" { /// use std::mem; /// use std::ptr; /// + /// # #[allow(dead_code)] /// fn swap(x: &mut T, y: &mut T) { /// unsafe { /// // Give ourselves some scratch space to work with @@ -372,6 +373,7 @@ extern "rust-intrinsic" { /// ``` /// use std::ptr; /// + /// # #[allow(dead_code)] /// unsafe fn from_buf_raw(ptr: *const T, elts: usize) -> Vec { /// let mut dst = Vec::with_capacity(elts); /// dst.set_len(elts); diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f1199919fcb0e..89227a9b2706d 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -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)); //! ``` @@ -401,7 +402,7 @@ pub trait Iterator { /// /// ``` /// // an infinite iterator has no upper bound - /// let iter = (0..); + /// let iter = 0..; /// /// assert_eq!((0, None), iter.size_hint()); /// ``` @@ -691,6 +692,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)); /// @@ -2669,7 +2671,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()); /// ``` @@ -2731,7 +2733,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()); /// ``` diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 94408072932ea..df7b7c437c3cc 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -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)] diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 5b5f59d5ddbb7..e7a350d2b1208 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -247,6 +247,7 @@ macro_rules! writeln { /// Match arms: /// /// ``` +/// # #[allow(dead_code)] /// fn foo(x: Option) { /// match x { /// Some(n) if n >= 0 => println!("Some(Non-negative)"), @@ -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"); } diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index f6baf23b564b0..2e1e76d77c375 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -42,6 +42,7 @@ impl !Send for *mut T { } /// `?Sized` can be used to remove this bound if it is not appropriate. /// /// ``` +/// # #![allow(dead_code)] /// struct Foo(T); /// struct Bar(T); /// @@ -106,6 +107,7 @@ pub trait Unsize { /// `struct` can be `Copy`: /// /// ``` +/// # #[allow(dead_code)] /// struct Point { /// x: i32, /// y: i32, @@ -115,6 +117,7 @@ pub trait Unsize { /// 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, @@ -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, @@ -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 { @@ -392,6 +397,8 @@ mod impls { /// #![feature(reflect_marker)] /// use std::marker::Reflect; /// use std::any::Any; +/// +/// # #[allow(dead_code)] /// fn foo(x: &T) { /// let any: &Any = x; /// if any.is::() { println!("u32"); } diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index a87d135e42592..2f01ea383400a 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -92,6 +92,7 @@ pub use intrinsics::transmute; /// use std::mem; /// use std::ptr; /// +/// # #[allow(dead_code)] /// fn swap(x: &mut T, y: &mut T) { /// unsafe { /// // Give ourselves some scratch space to work with @@ -151,6 +152,7 @@ pub fn size_of_val(val: &T) -> usize { /// # Examples /// /// ``` +/// # #![allow(deprecated)] /// use std::mem; /// /// assert_eq!(4, mem::min_align_of::()); @@ -167,6 +169,7 @@ pub fn min_align_of() -> usize { /// # Examples /// /// ``` +/// # #![allow(deprecated)] /// use std::mem; /// /// assert_eq!(4, mem::min_align_of_val(&5i32)); @@ -414,6 +417,7 @@ pub fn swap(x: &mut T, y: &mut T) { /// `self`, allowing it to be returned: /// /// ``` +/// # #![allow(dead_code)] /// use std::mem; /// # struct Buffer { buf: Vec } /// impl Buffer { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 582c091091fb2..cd4990e431bda 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -949,6 +949,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; @@ -998,6 +999,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; @@ -1047,6 +1049,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; @@ -1096,6 +1099,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; @@ -1145,6 +1149,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; @@ -1194,6 +1199,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; @@ -1243,6 +1249,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; @@ -1292,6 +1299,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; @@ -1341,6 +1349,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; @@ -1409,6 +1418,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; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 8fce64bd561dc..f9eea451b6d51 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -275,6 +275,7 @@ impl Option { /// /// ``` /// #![feature(as_slice)] + /// # #![allow(deprecated)] /// /// let mut x = Some("Diamonds"); /// { diff --git a/src/libcore/result.rs b/src/libcore/result.rs index ee3bfacd731c3..644e113dca833 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -16,6 +16,7 @@ //! and containing an error value. //! //! ``` +//! # #[allow(dead_code)] //! enum Result { //! 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; @@ -423,6 +428,7 @@ impl Result { /// /// ``` /// #![feature(as_slice)] + /// # #![allow(deprecated)] /// /// let mut x: Result<&str, u32> = Ok("Gold"); /// { diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 7a78460a841bd..d5961f0ceb4c7 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -142,8 +142,6 @@ impl Utf8Error { /// Basic usage: /// /// ``` - /// #![feature(utf8_error)] - /// /// use std::str; /// /// // some invalid bytes, in a vector From 589d82670c8810ff898c6fe4ec24efda3b87cd1f Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:28:58 +0000 Subject: [PATCH 07/27] libflate: deny warnings in doctests --- mk/tests.mk | 2 +- src/libflate/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 8fd4d80199441..dd4ab76df4fa9 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,7 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) arena +TEST_DOC_CRATES = $(DOC_CRATES) arena flate TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 521dddae78ff9..a1a0c42fe2758 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -23,7 +23,8 @@ #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] + html_root_url = "https://doc.rust-lang.org/nightly/", + test(attr(deny(warnings))))] #![feature(libc)] #![feature(staged_api)] From 623747ab0efbe0baa35f3a165b928458d69e9e70 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:30:14 +0000 Subject: [PATCH 08/27] libfmt_macros: deny warnings in doctests --- mk/tests.mk | 2 +- src/libfmt_macros/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index dd4ab76df4fa9..531d962a86530 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,7 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) arena flate +TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index ed767ab1e5cf9..dc69f38e4e7d0 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -24,7 +24,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![feature(staged_api)] #![feature(unicode)] From 6123df87ffe8c28dce6370474e992a107188cd24 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:32:48 +0000 Subject: [PATCH 09/27] libgetopts: deny warnings in doctests --- mk/tests.mk | 2 +- src/libgetopts/lib.rs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 531d962a86530..cd7e2510664ca 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,7 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros +TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index ab34f2e48ca4a..f49451f827d62 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -30,9 +30,11 @@ //! file name following `-o`, and accepts both `-h` and `--help` as optional flags. //! //! ```{.rust} +//! #![feature(rustc_private)] +//! //! extern crate getopts; //! use getopts::{optopt,optflag,getopts,OptGroup,usage}; -//! use std::os; +//! use std::env; //! //! fn do_work(inp: &str, out: Option) { //! println!("{}", inp); @@ -44,11 +46,11 @@ //! //! fn print_usage(program: &str, opts: &[OptGroup]) { //! let brief = format!("Usage: {} [options]", program); -//! print!("{}", usage(brief, opts)); +//! print!("{}", usage(&brief, opts)); //! } //! //! fn main() { -//! let args: Vec = os::args(); +//! let args: Vec = env::args().collect(); //! //! let program = args[0].clone(); //! @@ -56,22 +58,22 @@ //! optopt("o", "", "set output file name", "NAME"), //! optflag("h", "help", "print this help menu") //! ]; -//! let matches = match getopts(args[1..], opts) { +//! let matches = match getopts(&args[1..], opts) { //! Ok(m) => { m } //! Err(f) => { panic!(f.to_string()) } //! }; //! if matches.opt_present("h") { -//! print_usage(program, opts); +//! print_usage(&program, opts); //! return; //! } //! let output = matches.opt_str("o"); //! let input = if !matches.free.is_empty() { //! matches.free[0].clone() //! } else { -//! print_usage(program, opts); +//! print_usage(&program, opts); //! return; //! }; -//! do_work(input, output); +//! do_work(&input, output); //! } //! ``` @@ -88,7 +90,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![deny(missing_docs)] #![feature(staged_api)] From eb42797c007061c419725e38d1eccab76b03e9a8 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:33:58 +0000 Subject: [PATCH 10/27] libgraphviz: deny warnings in doctests --- mk/tests.mk | 2 +- src/libgraphviz/lib.rs | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index cd7e2510664ca..c34e6a3a2c512 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,7 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts +TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index b82b7d122b3ce..1fb54ed9071ab 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -47,7 +47,7 @@ //! which is cyclic. //! //! ```rust -//! #![feature(rustc_private, core, into_cow)] +//! #![feature(rustc_private, into_cow)] //! //! use std::borrow::IntoCow; //! use std::io::Write; @@ -150,9 +150,8 @@ //! entity `&sube`). //! //! ```rust -//! #![feature(rustc_private, core, into_cow)] +//! #![feature(rustc_private)] //! -//! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; //! @@ -174,10 +173,10 @@ //! dot::Id::new(format!("N{}", n)).unwrap() //! } //! fn node_label<'b>(&'b self, n: &Nd) -> dot::LabelText<'b> { -//! dot::LabelText::LabelStr(self.nodes[*n].as_slice().into_cow()) +//! dot::LabelText::LabelStr(self.nodes[*n].into()) //! } //! fn edge_label<'b>(&'b self, _: &Ed) -> dot::LabelText<'b> { -//! dot::LabelText::LabelStr("⊆".into_cow()) +//! dot::LabelText::LabelStr("⊆".into()) //! } //! } //! @@ -209,9 +208,8 @@ //! Hasse-diagram for the subsets of the set `{x, y}`. //! //! ```rust -//! #![feature(rustc_private, core, into_cow)] +//! #![feature(rustc_private)] //! -//! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; //! @@ -234,10 +232,10 @@ //! } //! fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> { //! let &(i, _) = n; -//! dot::LabelText::LabelStr(self.nodes[i].into_cow()) +//! dot::LabelText::LabelStr(self.nodes[i].into()) //! } //! fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> { -//! dot::LabelText::LabelStr("⊆".into_cow()) +//! dot::LabelText::LabelStr("⊆".into()) //! } //! } //! @@ -283,7 +281,8 @@ #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] + html_root_url = "https://doc.rust-lang.org/nightly/", + test(attr(allow(unused_variables), deny(warnings))))] #![feature(into_cow)] #![feature(str_escape)] From 2a0b283d0730c640d1cb12fda84b1d8062a1d5b9 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 15:58:36 +0000 Subject: [PATCH 11/27] liblibc: deny warnings in doctests --- src/liblibc/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 13902d674379e..ea16adea1677d 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -22,7 +22,8 @@ html_favicon_url = "https://doc.rust-lang.org/favicon.ico", 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/")] + issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", + test(attr(deny(warnings))))] #![cfg_attr(test, feature(test))] #![cfg_attr(not(feature = "cargo-build"), feature(cfg_target_vendor))] From d93ed29dd24d4f01497c0db574fff267130b519a Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:03:06 +0000 Subject: [PATCH 12/27] liblog: deny warnings in doctests --- mk/tests.mk | 3 ++- src/liblog/lib.rs | 4 +++- src/liblog/macros.rs | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index c34e6a3a2c512..dc646e3bccdd7 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -25,7 +25,8 @@ $(eval $(call RUST_CRATE,collectionstest)) TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest -TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz +TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ + log TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 9cb835bd8525d..1de7ebfffdea2 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -13,6 +13,7 @@ //! # Examples //! //! ``` +//! # #![feature(rustc_private)] //! #[macro_use] extern crate log; //! //! fn main() { @@ -167,7 +168,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![deny(missing_docs)] #![feature(box_syntax)] diff --git a/src/liblog/macros.rs b/src/liblog/macros.rs index 46b51f50c8583..803a2df9ccc8b 100644 --- a/src/liblog/macros.rs +++ b/src/liblog/macros.rs @@ -19,6 +19,7 @@ /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// /// fn main() { @@ -67,6 +68,7 @@ macro_rules! log { /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// /// fn main() { @@ -92,6 +94,7 @@ macro_rules! error { /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// /// fn main() { @@ -116,6 +119,7 @@ macro_rules! warn { /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// /// fn main() { @@ -142,6 +146,7 @@ macro_rules! info { /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// /// fn main() { @@ -165,9 +170,10 @@ macro_rules! debug { /// # Examples /// /// ``` +/// # #![feature(rustc_private)] /// #[macro_use] extern crate log; /// -/// struct Point { x: int, y: int } +/// struct Point { x: i32, y: i32 } /// fn some_expensive_computation() -> Point { Point { x: 1, y: 2 } } /// /// fn main() { From 8100f7f2cdee702a42cd1a5f3c70e79798cc50b9 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:04:40 +0000 Subject: [PATCH 13/27] librand: deny warnings in doctests --- mk/tests.mk | 2 +- src/librand/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index dc646e3bccdd7..b4e997f99addf 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log + log rand TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/librand/lib.rs b/src/librand/lib.rs index b5a1eb9520cec..cf2118b45a471 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -23,7 +23,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![no_std] #![staged_api] #![unstable(feature = "rand", From cc39abbcc39a912c621fb77fe54d851a713f7f5a Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:06:02 +0000 Subject: [PATCH 14/27] librbml: deny warnings in doctests --- mk/tests.mk | 2 +- src/librbml/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index b4e997f99addf..b9afe24201b45 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log rand + log rand rbml TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 1c6cb06d54ae4..a1b15cd9e6f11 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -121,7 +121,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![feature(rustc_private)] #![feature(staged_api)] From 640aab359ed01f14f956d6e1225187378718f5bc Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:12:25 +0000 Subject: [PATCH 15/27] librustc_unicode: deny warnings in doctests --- src/librustc_unicode/lib.rs | 2 +- src/librustc_unicode/u_str.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_unicode/lib.rs b/src/librustc_unicode/lib.rs index 467c974690062..79ce8aacae815 100644 --- a/src/librustc_unicode/lib.rs +++ b/src/librustc_unicode/lib.rs @@ -31,7 +31,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/", - test(no_crate_inject))] + test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] #![feature(core_char_ext)] diff --git a/src/librustc_unicode/u_str.rs b/src/librustc_unicode/u_str.rs index 2347cdebf2292..57d96bf43719e 100644 --- a/src/librustc_unicode/u_str.rs +++ b/src/librustc_unicode/u_str.rs @@ -190,6 +190,7 @@ impl<'a> Iterator for Utf16Items<'a> { /// /// ``` /// #![feature(unicode, decode_utf16)] +/// # #![allow(deprecated)] /// /// extern crate rustc_unicode; /// From 569f29ca9924c48abadaca026d7d71b3bd6722f1 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:17:57 +0000 Subject: [PATCH 16/27] libserialize: deny warnings in doctests --- mk/tests.mk | 2 +- src/libserialize/json.rs | 9 ++++++--- src/libserialize/lib.rs | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index b9afe24201b45..b26c2336d8689 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log rand rbml + log rand rbml serialize TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 452feed3cdb4e..9e1e3c6a55805 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -77,8 +77,9 @@ //! serialization API, using the derived serialization code. //! //! ```rust -//! extern crate serialize; -//! use serialize::json; +//! # #![feature(rustc_private)] +//! extern crate serialize as rustc_serialize; // for the deriving below +//! use rustc_serialize::json; //! //! // Automatically generate `Decodable` and `Encodable` trait implementations //! #[derive(RustcDecodable, RustcEncodable)] @@ -111,6 +112,7 @@ //! ### Simple example of `ToJson` usage //! //! ```rust +//! # #![feature(rustc_private)] //! extern crate serialize; //! use serialize::json::{self, ToJson, Json}; //! @@ -150,6 +152,7 @@ //! ### Verbose example of `ToJson` usage //! //! ```rust +//! # #![feature(rustc_private)] //! extern crate serialize; //! use std::collections::BTreeMap; //! use serialize::json::{self, Json, ToJson}; @@ -185,7 +188,7 @@ //! let json_str: String = json_obj.to_string(); //! //! // Deserialize like before -//! let decoded: TestStruct = json::decode(json_str)).unwrap(); +//! let decoded: TestStruct = json::decode(&json_str).unwrap(); //! } //! ``` diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 5b7bec41723cd..4a766f1453137 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -26,7 +26,8 @@ Core encoding and decoding interfaces. #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(allow(unused_variables), deny(warnings))))] #![feature(box_syntax)] #![feature(collections)] From ba24a03eda4138f07fd71e6ad951eb6a213788db Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:34:11 +0000 Subject: [PATCH 17/27] libsyntax: deny warnings in doctests --- mk/tests.mk | 2 +- src/libsyntax/ast.rs | 14 ++++++++------ src/libsyntax/ext/deriving/generic/mod.rs | 9 +++++---- src/libsyntax/ext/format.rs | 7 ++++--- src/libsyntax/lib.rs | 3 ++- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pp.rs | 6 ++++-- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index b26c2336d8689..f15546c1b6680 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log rand rbml serialize + log rand rbml serialize syntax TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e56e49c4f4902..6335763f70479 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -909,13 +909,15 @@ pub enum Expr_ { /// separately. `position` represents the index of the associated /// item qualified with this Self type. /// -/// as a::b::Trait>::AssociatedItem -/// ^~~~~ ~~~~~~~~~~~~~~^ -/// ty position = 3 +/// ```ignore +/// as a::b::Trait>::AssociatedItem +/// ^~~~~ ~~~~~~~~~~~~~~^ +/// ty position = 3 /// -/// >::AssociatedItem -/// ^~~~~ ^ -/// ty position = 0 +/// >::AssociatedItem +/// ^~~~~ ^ +/// ty position = 0 +/// ``` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct QSelf { pub ty: P, diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 5c6e2fce8adce..5a0fc4fda0cca 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -54,6 +54,7 @@ //! following snippet //! //! ```rust +//! # #![allow(dead_code)] //! struct A { x : i32 } //! //! struct B(i32); @@ -88,7 +89,7 @@ //! //! ```rust //! trait PartialEq { -//! fn eq(&self, other: &Self); +//! fn eq(&self, other: &Self) -> bool; //! } //! impl PartialEq for i32 { //! fn eq(&self, other: &i32) -> bool { @@ -905,7 +906,7 @@ impl<'a> MethodDef<'a> { }) } - /// ``` + /// ```ignore /// #[derive(PartialEq)] /// struct A { x: i32, y: i32 } /// @@ -1010,7 +1011,7 @@ impl<'a> MethodDef<'a> { &StaticStruct(struct_def, summary)) } - /// ``` + /// ```ignore /// #[derive(PartialEq)] /// enum A { /// A1, @@ -1596,7 +1597,7 @@ pub fn cs_fold(use_foldl: bool, /// Call the method that is being derived on all the fields, and then /// process the collected results. i.e. /// -/// ``` +/// ```ignore /// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1), /// self_2.method(__arg_1_2, __arg_2_2)]) /// ``` diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index c56342371c84e..af0e7ce5c8d36 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -77,9 +77,10 @@ struct Context<'a, 'b:'a> { /// expressions. /// /// If parsing succeeds, the return value is: -/// -/// Some((fmtstr, unnamed arguments, ordering of named arguments, -/// named arguments)) +/// ```ignore +/// Some((fmtstr, unnamed arguments, ordering of named arguments, +/// named arguments)) +/// ``` fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Option<(P, Vec>, Vec, HashMap>)> { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 8b001f2419c56..295c3e05bc012 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -23,7 +23,8 @@ #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] + html_root_url = "https://doc.rust-lang.org/nightly/", + test(attr(deny(warnings))))] #![feature(associated_consts)] #![feature(drain)] diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2401f6be78f9c..410c9af7a1561 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3959,7 +3959,7 @@ impl<'a> Parser<'a> { /// Parses an optional `where` clause and places it in `generics`. /// - /// ``` + /// ```ignore /// where T : Trait + 'b, 'a : 'b /// ``` pub fn parse_where_clause(&mut self) -> PResult { diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 7c5a46465f513..cbbd5289a5a2d 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -11,8 +11,10 @@ //! This pretty-printer is a direct reimplementation of Philip Karlton's //! Mesa pretty-printer, as described in appendix A of //! -//! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen. -//! Stanford Department of Computer Science, 1979. +//! ````ignore +//! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen. +//! Stanford Department of Computer Science, 1979. +//! ```` //! //! The algorithm's aim is to break a stream into as few lines as possible //! while respecting the indentation-consistency requirements of the enclosing From 50173f2ecdcccc2769dbe7f8482459283def1d8f Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:35:33 +0000 Subject: [PATCH 18/27] libterm: deny warnings in doctests --- mk/tests.mk | 2 +- src/libterm/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index f15546c1b6680..70ebd092aea00 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log rand rbml serialize syntax + log rand rbml serialize syntax term TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index ced3a7d47d7b6..99bbd951766c6 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -53,7 +53,8 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_playground_url = "https://play.rust-lang.org/", + test(attr(deny(warnings))))] #![deny(missing_docs)] #![feature(box_syntax)] From fb271725e2b6e4a9832b694a0264b32436cd7704 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:37:29 +0000 Subject: [PATCH 19/27] libtest: deny warnings in doctests --- mk/tests.mk | 2 +- src/libtest/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 70ebd092aea00..39186a4d1e2a5 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -26,7 +26,7 @@ TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \ - log rand rbml serialize syntax term + log rand rbml serialize syntax term test TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \ rustc_trans rustc_lint,\ $(HOST_CRATES)) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 12541dc010bcf..0805480e558fd 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -32,7 +32,8 @@ #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] + html_root_url = "https://doc.rust-lang.org/nightly/", + test(attr(deny(warnings))))] #![feature(asm)] #![feature(box_syntax)] From 956986a99e8d854c2b53e0e2e012f965982a6ef9 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 16:42:25 +0000 Subject: [PATCH 20/27] trpl: add a small section outlining doctest configuration --- src/doc/trpl/documentation.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index e101d4bc0d4dc..9e97c4f2a27cb 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -590,6 +590,18 @@ You can control a few aspects of the HTML that `rustdoc` generates through the This sets a few different options, with a logo, favicon, and a root URL. +### Configuring documentation tests + +You can also configure the way that `rustdoc` tests your documentation examples +through the `#![doc(test(..))]` attribute. + +```rust +#![doc(test(attr(allow(unused_variables), deny(warnings))))] +``` + +This allows unused variables within the examples, but will fail the test for any +other lint warning thrown. + ## Generation options `rustdoc` also contains a few other options on the command line, for further customization: From 46b30ccd895d6fc990474cb6f130b41d0a9b8dcf Mon Sep 17 00:00:00 2001 From: Eric Findlay Date: Sun, 8 Nov 2015 10:03:58 +0900 Subject: [PATCH 21/27] Added foo() to rustdoc example, r=steveklabnik Fixes #29234 --- src/doc/trpl/documentation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 191a51dffdbfc..b3f79f2f1df9c 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -385,17 +385,17 @@ error handling. Lets say you want the following, The problem is that `try!` returns a `Result` and test functions don't return anything so this will give a mismatched types error. -```rust +```rust,ignore /// A doc test using try! /// /// ``` /// use std::io; -/// # fn f() -> io::Result<()> { +/// # fn foo() -> io::Result<()> { /// let mut input = String::new(); /// try!(io::stdin().read_line(&mut input)); /// # Ok(()) /// # } -/// # f(); +/// # foo(); /// ``` ``` From dda7a3c2a195b7d99f4173f3636a8a7d25ca8c0c Mon Sep 17 00:00:00 2001 From: Eric Findlay Date: Sun, 8 Nov 2015 11:00:03 +0900 Subject: [PATCH 22/27] Fixed "foo()" in try! example, r=steveklabnik --- src/doc/trpl/documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index b3f79f2f1df9c..dc91c90b0fd62 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -395,8 +395,8 @@ don't return anything so this will give a mismatched types error. /// try!(io::stdin().read_line(&mut input)); /// # Ok(()) /// # } -/// # foo(); /// ``` +# fn foo() {} ``` You can get around this by wrapping the code in a function. This catches From e3433e3b519dfaddedd5f18a514604a779799da3 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sun, 8 Nov 2015 17:17:02 +0300 Subject: [PATCH 23/27] Fix outdated comment in Vec::from_iter Since commit 46068c9da, call to `reserve()` on empty vec allocates exactly requested capacity, so unroll of first iteration may help only with branch prediction. --- src/libcollections/vec.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 716a07be2b4b2..c4e4059429f38 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1220,8 +1220,7 @@ impl FromIterator for Vec { // expanded on this iteration in every case when the iterable is not // empty, but the loop in extend_desugared() is not going to see the // vector being full in the few subsequent loop iterations. - // So we get better branch prediction and the possibility to - // construct the vector with initial estimated capacity. + // So we get better branch prediction. let mut iterator = iterable.into_iter(); let mut vector = match iterator.next() { None => return Vec::new(), From 621e259b78fb992745c3cf194e28be5a8610a97c Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Mon, 9 Nov 2015 03:42:22 +0000 Subject: [PATCH 24/27] libstd: add example for PathBuf::push --- src/libstd/path.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b9a58a117643a..6b5e16ae113b3 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1013,6 +1013,21 @@ impl PathBuf { /// * if `path` has a root but no prefix (e.g. `\windows`), it /// replaces everything except for the prefix (if any) of `self`. /// * if `path` has a prefix but no root, it replaces `self`. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let mut path = PathBuf::new(); + /// path.push("/tmp"); + /// path.push("file.bk"); + /// assert_eq!(path, PathBuf::from("/tmp/file.bk")); + /// + /// // Pushing an absolute path replaces the current path + /// path.push("/etc/passwd"); + /// assert_eq!(path, PathBuf::from("/etc/passwd")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push>(&mut self, path: P) { self._push(path.as_ref()) From c618c5f36a3260351a09f4b4dc51b2e5d1359fbc Mon Sep 17 00:00:00 2001 From: Ivan Ivaschenko Date: Mon, 9 Nov 2015 17:49:30 +0200 Subject: [PATCH 25/27] Doc: Fix broken link on for-loop.html --- src/doc/trpl/dining-philosophers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/dining-philosophers.md b/src/doc/trpl/dining-philosophers.md index 5f66a5b9e297c..50d758c3a108f 100644 --- a/src/doc/trpl/dining-philosophers.md +++ b/src/doc/trpl/dining-philosophers.md @@ -232,7 +232,7 @@ also called a ‘vector’, and it’s a growable array type. We then use a [`for`][for] loop to iterate through the vector, getting a reference to each philosopher in turn. -[for]: for-loops.html +[for]: loops.html#for In the body of the loop, we call `p.eat()`, which is defined above: From 779382987761c2835fc2eaced46995a780bc4b0e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 9 Nov 2015 13:22:16 -0800 Subject: [PATCH 26/27] Redo the README intro again --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5e208a76e0315..8eb742f0a22fc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,9 @@ # The Rust Programming Language -Rust is a fast systems programming language that guarantees -memory safety and offers painless concurrency ([no data races]). -It does not employ a garbage collector and has minimal runtime overhead. +This is the main source code repository for [Rust]. It contains the compiler, standard library, +and documentation. -This repo contains the code for the compiler (`rustc`), as well -as standard libraries, tools and documentation for Rust. - -[no data races]: http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html +[Rust]: https://www.rust-lang.org ## Quick Start From abb9c9008fbb253f82dfc0e7c72dcd107e820fb7 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 10 Nov 2015 01:39:23 +0100 Subject: [PATCH 27/27] Some cleanup on after #29684 * wrap to 80 cols * small grammar fix, missing 'the' --- src/libcore/iter.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index da7d673cd96b4..f8c6e3cfdd7dd 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -371,22 +371,21 @@ pub trait Iterator { /// /// # Implementation notes /// - /// It is not enforced that an iterator implementation yields the - /// declared number of elements. A buggy iterator may yield less - /// than the lower bound or more than the upper bound of elements. + /// It is not enforced that an iterator implementation yields the declared + /// number of elements. A buggy iterator may yield less than the lower bound + /// or more than the upper bound of elements. /// - /// `size_hint()` is primarily intended to be used for optimizations - /// such as reserving space for the elements of the iterator, but - /// must not be trusted to e.g. omit bounds checks in unsafe code. - /// An incorrect implementation of `size_hint()` should not lead to - /// memory safety violations. + /// `size_hint()` is primarily intended to be used for optimizations such as + /// reserving space for the elements of the iterator, but must not be + /// trusted to e.g. omit bounds checks in unsafe code. An incorrect + /// implementation of `size_hint()` should not lead to memory safety + /// violations. /// - /// That said, the implementation should provide a correct - /// estimation, because otherwise it would be a violation of the - /// trait's protocol. + /// That said, the implementation should provide a correct estimation, + /// because otherwise it would be a violation of the trait's protocol. /// - /// The default implementation returns `(0, None)` which is correct - /// for any iterator. + /// The default implementation returns `(0, None)` which is correct for any + /// iterator. /// /// # Examples /// @@ -2750,7 +2749,7 @@ pub trait ExactSizeIterator: Iterator { /// implementation, you can do so. See the [trait-level] docs for an /// example. /// - /// This function has the same safety guarantees as [`size_hint()`] + /// This function has the same safety guarantees as the [`size_hint()`] /// function. /// /// [trait-level]: trait.ExactSizeIterator.html