Skip to content

Commit b747425

Browse files
authored
Rollup merge of rust-lang#56689 - QuietMisdreavus:rustdoc-lint-group, r=pnkfelix
add a lint group for lints emitted by rustdoc As rustdoc adds more lints that it specifically manages, it would be nice to be able to lump them all together. This gives us a new group just for that. I deliberately didn't include `missing_docs` because this is kind of a stepping stone for moving our lints into tool lints (i.e. `#![warn(rustdoc::private_doc_tests)]`), since all of these are specifically emitted by rustdoc. If we want to move `missing_docs` out of the compiler, that's also an option, but it would create a surprising change of behavior. I also took the chance to rewrite the lint descriptions of these lints to better match the style of the other lints. `>_>`
2 parents d3f6d61 + 55d20bf commit b747425

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

src/librustc/lint/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,19 @@ declare_lint! {
315315
declare_lint! {
316316
pub INTRA_DOC_LINK_RESOLUTION_FAILURE,
317317
Warn,
318-
"warn about documentation intra links resolution failure"
318+
"failures in resolving intra-doc link targets"
319319
}
320320

321321
declare_lint! {
322322
pub MISSING_DOC_CODE_EXAMPLES,
323323
Allow,
324-
"warn about missing code example in an item's documentation"
324+
"detects publicly-exported items without code samples in their documentation"
325325
}
326326

327327
declare_lint! {
328328
pub PRIVATE_DOC_TESTS,
329329
Allow,
330-
"warn about doc test in private item"
330+
"detects code samples in docs of private items not documented by rustdoc"
331331
}
332332

333333
declare_lint! {

src/librustc_lint/lib.rs

+9
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

+34
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

+44
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)