Skip to content

Commit 8c9c951

Browse files
committed
Auto merge of #29544 - Ryman:reduce_doc_warnings, r=steveklabnik
Did this alphabetically, so I didn't see [how `std` was doing things](https://dxr.mozilla.org/rust/source/src/libstd/lib.rs#215) till I was nearly finished. If you prefer to add crate-level-whitelists like std instead of test-level, I can rebase with that strategy. A number of these commits can probably be dropped as the crates don't have much to test, and are deprecated. Let me know which if any to drop! (can also squash after review if desired) r? @steveklabnik
2 parents 0bd7084 + 5ae1937 commit 8c9c951

File tree

47 files changed

+168
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+168
-69
lines changed

mk/tests.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ $(eval $(call RUST_CRATE,collectionstest))
2525
TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
2626
alloc_jemalloc,$(TARGET_CRATES)) \
2727
collectionstest coretest
28-
TEST_DOC_CRATES = $(DOC_CRATES)
28+
TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \
29+
log rand rbml serialize syntax term test
2930
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \
3031
rustc_trans rustc_lint,\
3132
$(HOST_CRATES))

src/doc/trpl/documentation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@ You can control a few aspects of the HTML that `rustdoc` generates through the
620620

621621
This sets a few different options, with a logo, favicon, and a root URL.
622622

623+
### Configuring documentation tests
624+
625+
You can also configure the way that `rustdoc` tests your documentation examples
626+
through the `#![doc(test(..))]` attribute.
627+
628+
```rust
629+
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
630+
```
631+
632+
This allows unused variables within the examples, but will fail the test for any
633+
other lint warning thrown.
634+
623635
## Generation options
624636

625637
`rustdoc` also contains a few other options on the command line, for further customization:

src/liballoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
7171
html_root_url = "https://doc.rust-lang.org/nightly/",
7272
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
73-
test(no_crate_inject))]
73+
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
7474
#![no_std]
7575
#![cfg_attr(not(stage0), needs_allocator)]
7676

src/libarena/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#![crate_type = "dylib"]
2929
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
3030
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
31-
html_root_url = "https://doc.rust-lang.org/nightly/")]
31+
html_root_url = "https://doc.rust-lang.org/nightly/",
32+
test(no_crate_inject, attr(deny(warnings))))]
3233

3334
#![feature(alloc)]
3435
#![feature(box_syntax)]

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl<T: Ord> BinaryHeap<T> {
233233
///
234234
/// ```
235235
/// #![feature(binary_heap_extras)]
236+
/// # #![allow(deprecated)]
236237
///
237238
/// use std::collections::BinaryHeap;
238239
/// let heap = BinaryHeap::from_vec(vec![9, 1, 2, 7, 3, 2]);

src/libcollections/borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl<T> ToOwned for T where T: Clone {
7272
/// ```
7373
/// use std::borrow::Cow;
7474
///
75+
/// # #[allow(dead_code)]
7576
/// fn abs_all(input: &mut Cow<[i32]>) {
7677
/// for i in 0..input.len() {
7778
/// let v = input[i];

src/libcollections/btree/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl<T: Ord> BTreeSet<T> {
8989
/// # Examples
9090
///
9191
/// ```
92+
/// # #![allow(unused_mut)]
9293
/// use std::collections::BTreeSet;
9394
///
9495
/// let mut set: BTreeSet<i32> = BTreeSet::new();

src/libcollections/fmt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
//! implement a method of the signature:
151151
//!
152152
//! ```
153+
//! # #![allow(dead_code)]
153154
//! # use std::fmt;
154155
//! # struct Foo; // our custom type
155156
//! # impl fmt::Display for Foo {
@@ -174,7 +175,6 @@
174175
//! like:
175176
//!
176177
//! ```
177-
//! #![feature(fmt_flags)]
178178
//! use std::fmt;
179179
//!
180180
//! #[derive(Debug)]
@@ -288,6 +288,7 @@
288288
//! off, some example usage is:
289289
//!
290290
//! ```
291+
//! # #![allow(unused_must_use)]
291292
//! use std::fmt;
292293
//! use std::io::{self, Write};
293294
//!

src/libcollections/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
html_root_url = "https://doc.rust-lang.org/nightly/",
2828
html_playground_url = "https://play.rust-lang.org/",
2929
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
30-
test(no_crate_inject))]
30+
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
3131

3232
#![allow(trivial_casts)]
3333
#![cfg_attr(test, allow(deprecated))] // rand

src/libcollections/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ pub trait SliceConcatExt<T: ?Sized> {
852852
/// # Examples
853853
///
854854
/// ```
855+
/// # #![allow(deprecated)]
855856
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
856857
/// ```
857858
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)