Skip to content

Commit 48c17a0

Browse files
add a lint group for lints emitted by rustdoc
1 parent 1137d29 commit 48c17a0

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

src/librustc_lint/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ use rustc::lint::builtin::{
5353
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
5454
ELIDED_LIFETIMES_IN_PATHS,
5555
EXPLICIT_OUTLIVES_REQUIREMENTS,
56+
INTRA_DOC_LINK_RESOLUTION_FAILURE,
57+
MISSING_DOC_CODE_EXAMPLES,
58+
PRIVATE_DOC_TESTS,
5659
parser::QUESTION_MARK_MACRO_SEP
5760
};
5861
use rustc::session;
@@ -204,6 +207,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
204207
// MACRO_USE_EXTERN_CRATE,
205208
);
206209

210+
add_lint_group!(sess,
211+
"rustdoc",
212+
INTRA_DOC_LINK_RESOLUTION_FAILURE,
213+
MISSING_DOC_CODE_EXAMPLES,
214+
PRIVATE_DOC_TESTS);
215+
207216
// Guidelines for creating a future incompatibility lint:
208217
//
209218
// - Create a lint defaulting to warn as normal, with ideally the same error

src/test/rustdoc-ui/lint-group.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Documenting the kinds of lints emitted by rustdoc.
12+
//!
13+
//! ```
14+
//! println!("sup");
15+
//! ```
16+
17+
#![deny(rustdoc)]
18+
19+
/// what up, let's make an [error]
20+
///
21+
/// ```
22+
/// println!("sup");
23+
/// ```
24+
pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it
25+
26+
/// wait, this doesn't have a doctest?
27+
pub fn no_doctest() {} //~^ ERROR Missing code example in this documentation
28+
29+
/// wait, this *does* have a doctest?
30+
///
31+
/// ```
32+
/// println!("sup");
33+
/// ```
34+
fn private_doctest() {} //~^^^^^ ERROR Documentation test in private item

src/test/rustdoc-ui/lint-group.stderr

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error: Documentation test in private item
2+
--> $DIR/lint-group.rs:29:1
3+
|
4+
LL | / /// wait, this *does* have a doctest?
5+
LL | | ///
6+
LL | | /// ```
7+
LL | | /// println!("sup");
8+
LL | | /// ```
9+
| |_______^
10+
|
11+
note: lint level defined here
12+
--> $DIR/lint-group.rs:17:9
13+
|
14+
LL | #![deny(rustdoc)]
15+
| ^^^^^^^
16+
= note: #[deny(private_doc_tests)] implied by #[deny(rustdoc)]
17+
18+
error: `[error]` cannot be resolved, ignoring it...
19+
--> $DIR/lint-group.rs:19:29
20+
|
21+
LL | /// what up, let's make an [error]
22+
| ^^^^^ cannot be resolved, ignoring
23+
|
24+
note: lint level defined here
25+
--> $DIR/lint-group.rs:17:9
26+
|
27+
LL | #![deny(rustdoc)]
28+
| ^^^^^^^
29+
= note: #[deny(intra_doc_link_resolution_failure)] implied by #[deny(rustdoc)]
30+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
31+
32+
error: Missing code example in this documentation
33+
--> $DIR/lint-group.rs:26:1
34+
|
35+
LL | /// wait, this doesn't have a doctest?
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
|
38+
note: lint level defined here
39+
--> $DIR/lint-group.rs:17:9
40+
|
41+
LL | #![deny(rustdoc)]
42+
| ^^^^^^^
43+
= note: #[deny(missing_doc_code_examples)] implied by #[deny(rustdoc)]
44+

0 commit comments

Comments
 (0)