Skip to content

Commit ac92cc8

Browse files
Rollup merge of #101732 - Nemo157:gate-rustdoc-missing-examples, r=GuillaumeGomez
Feature gate the `rustdoc::missing_doc_code_examples` lint Moves the lint from being implicitly active on nightly `rustdoc` to requiring a feature to activate, like other unstable lints. Uses the new tracking issue #101730
2 parents 05a267f + 72cf46a commit ac92cc8

18 files changed

+104
-42
lines changed

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ declare_features! (
221221
(active, rustc_private, "1.0.0", Some(27812), None),
222222
/// Allows using internal rustdoc features like `doc(primitive)` or `doc(keyword)`.
223223
(active, rustdoc_internals, "1.58.0", Some(90418), None),
224+
/// Allows using the `rustdoc::missing_doc_code_examples` lint
225+
(active, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730), None),
224226
/// Allows using `#[start]` on a function indicating that it is the program entrypoint.
225227
(active, start, "1.0.0", Some(29633), None),
226228
/// Allows using `#[structural_match]` which indicates that a type is structurally matchable.

compiler/rustc_lint/src/levels.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,10 @@ impl<'s> LintLevelsBuilder<'s> {
440440
sp,
441441
reason,
442442
);
443-
for id in ids {
444-
self.insert_spec(*id, (level, src));
443+
for &id in ids {
444+
if self.check_gated_lint(id, attr.span) {
445+
self.insert_spec(id, (level, src));
446+
}
445447
}
446448
if let Level::Expect(expect_id) = level {
447449
self.lint_expectations.push((

compiler/rustc_lint_defs/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -658,18 +658,21 @@ macro_rules! declare_lint {
658658
macro_rules! declare_tool_lint {
659659
(
660660
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
661+
$(, @feature_gate = $gate:expr;)?
661662
) => (
662-
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
663+
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?}
663664
);
664665
(
665666
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
666667
report_in_external_macro: $rep:expr
668+
$(, @feature_gate = $gate:expr;)?
667669
) => (
668-
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
670+
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?}
669671
);
670672
(
671673
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
672674
$external:expr
675+
$(, @feature_gate = $gate:expr;)?
673676
) => (
674677
$(#[$attr])*
675678
$vis static $NAME: &$crate::Lint = &$crate::Lint {
@@ -680,8 +683,9 @@ macro_rules! declare_tool_lint {
680683
report_in_external_macro: $external,
681684
future_incompatible: None,
682685
is_plugin: true,
683-
feature_gate: None,
686+
$(feature_gate: Some($gate),)?
684687
crate_level_only: false,
688+
..$crate::Lint::default_fields_for_macro()
685689
};
686690
);
687691
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ symbols! {
12921292
rustc_variance,
12931293
rustdoc,
12941294
rustdoc_internals,
1295+
rustdoc_missing_doc_code_examples,
12951296
rustfmt,
12961297
rvalue_static_promotion,
12971298
s,

src/librustdoc/lint.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ where
6464
}
6565

6666
macro_rules! declare_rustdoc_lint {
67-
($(#[$attr:meta])* $name: ident, $level: ident, $descr: literal $(,)?) => {
67+
(
68+
$(#[$attr:meta])* $name: ident, $level: ident, $descr: literal $(,)?
69+
$(@feature_gate = $gate:expr;)?
70+
) => {
6871
declare_tool_lint! {
6972
$(#[$attr])* pub rustdoc::$name, $level, $descr
73+
$(, @feature_gate = $gate;)?
7074
}
7175
}
7276
}
@@ -123,7 +127,8 @@ declare_rustdoc_lint! {
123127
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
124128
MISSING_DOC_CODE_EXAMPLES,
125129
Allow,
126-
"detects publicly-exported items without code samples in their documentation"
130+
"detects publicly-exported items without code samples in their documentation",
131+
@feature_gate = rustc_span::symbol::sym::rustdoc_missing_doc_code_examples;
127132
}
128133

129134
declare_rustdoc_lint! {

src/librustdoc/passes/check_doc_test_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
117117

118118
find_testable_code(dox, &mut tests, ErrorCodes::No, false, None);
119119

120-
if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() {
120+
if tests.found_tests == 0 && cx.tcx.features().rustdoc_missing_doc_code_examples {
121121
if should_have_doc_example(cx, item) {
122122
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
123123
let sp = item.attr_span(cx.tcx);

src/test/rustdoc-ui/check-fail.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: -Z unstable-options --check
22

3+
#![feature(rustdoc_missing_doc_code_examples)]
34
#![deny(missing_docs)]
45
#![deny(rustdoc::all)]
56

src/test/rustdoc-ui/check-fail.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
error: missing documentation for a function
2-
--> $DIR/check-fail.rs:11:1
2+
--> $DIR/check-fail.rs:12:1
33
|
44
LL | pub fn foo() {}
55
| ^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/check-fail.rs:3:9
8+
--> $DIR/check-fail.rs:4:9
99
|
1010
LL | #![deny(missing_docs)]
1111
| ^^^^^^^^^^^^
1212

1313
error: missing code example in this documentation
14-
--> $DIR/check-fail.rs:11:1
14+
--> $DIR/check-fail.rs:12:1
1515
|
1616
LL | pub fn foo() {}
1717
| ^^^^^^^^^^^^^^^
1818
|
1919
note: the lint level is defined here
20-
--> $DIR/check-fail.rs:4:9
20+
--> $DIR/check-fail.rs:5:9
2121
|
2222
LL | #![deny(rustdoc::all)]
2323
| ^^^^^^^^^^^^
2424
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc::all)]`
2525

2626
error: unknown attribute `testharness`. Did you mean `test_harness`?
27-
--> $DIR/check-fail.rs:6:1
27+
--> $DIR/check-fail.rs:7:1
2828
|
2929
LL | / //! ```rust,testharness
3030
LL | |
@@ -36,7 +36,7 @@ LL | | //! ```
3636
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
3737

3838
error: unknown attribute `testharness`. Did you mean `test_harness`?
39-
--> $DIR/check-fail.rs:15:1
39+
--> $DIR/check-fail.rs:16:1
4040
|
4141
LL | / /// hello
4242
LL | |

src/test/rustdoc-ui/check.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// compile-flags: -Z unstable-options --check
33
// normalize-stderr-test: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
44

5-
#![warn(missing_docs)]
5+
#![feature(rustdoc_missing_doc_code_examples)]
66
//~^ WARN
77
//~^^ WARN
8+
9+
#![warn(missing_docs)]
810
#![warn(rustdoc::all)]
911

1012
pub fn foo() {}

src/test/rustdoc-ui/check.stderr

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
warning: missing documentation for the crate
22
--> $DIR/check.rs:5:1
33
|
4-
LL | / #![warn(missing_docs)]
4+
LL | / #![feature(rustdoc_missing_doc_code_examples)]
55
LL | |
66
LL | |
7-
LL | | #![warn(rustdoc::all)]
7+
LL | |
8+
... |
89
LL | |
910
LL | | pub fn foo() {}
1011
| |_______________^
1112
|
1213
note: the lint level is defined here
13-
--> $DIR/check.rs:5:9
14+
--> $DIR/check.rs:9:9
1415
|
1516
LL | #![warn(missing_docs)]
1617
| ^^^^^^^^^^^^
1718

1819
warning: missing documentation for a function
19-
--> $DIR/check.rs:10:1
20+
--> $DIR/check.rs:12:1
2021
|
2122
LL | pub fn foo() {}
2223
| ^^^^^^^^^^^^
2324

2425
warning: no documentation found for this crate's top-level module
2526
|
2627
note: the lint level is defined here
27-
--> $DIR/check.rs:8:9
28+
--> $DIR/check.rs:10:9
2829
|
2930
LL | #![warn(rustdoc::all)]
3031
| ^^^^^^^^^^^^
@@ -35,18 +36,19 @@ LL | #![warn(rustdoc::all)]
3536
warning: missing code example in this documentation
3637
--> $DIR/check.rs:5:1
3738
|
38-
LL | / #![warn(missing_docs)]
39+
LL | / #![feature(rustdoc_missing_doc_code_examples)]
40+
LL | |
3941
LL | |
4042
LL | |
41-
LL | | #![warn(rustdoc::all)]
43+
... |
4244
LL | |
4345
LL | | pub fn foo() {}
4446
| |_______________^
4547
|
4648
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc::all)]`
4749

4850
warning: missing code example in this documentation
49-
--> $DIR/check.rs:10:1
51+
--> $DIR/check.rs:12:1
5052
|
5153
LL | pub fn foo() {}
5254
| ^^^^^^^^^^^^^^^

src/test/rustdoc-ui/doc-without-codeblock.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![deny(rustdoc::missing_doc_code_examples)] //~ ERROR missing code example in this documentation
1+
#![feature(rustdoc_missing_doc_code_examples)] //~ ERROR missing code example in this documentation
2+
#![deny(rustdoc::missing_doc_code_examples)]
23

34
/// Some docs.
45
//~^ ERROR missing code example in this documentation

src/test/rustdoc-ui/doc-without-codeblock.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: missing code example in this documentation
22
--> $DIR/doc-without-codeblock.rs:1:1
33
|
4-
LL | / #![deny(rustdoc::missing_doc_code_examples)]
4+
LL | / #![feature(rustdoc_missing_doc_code_examples)]
5+
LL | | #![deny(rustdoc::missing_doc_code_examples)]
56
LL | |
67
LL | | /// Some docs.
7-
LL | |
88
... |
99
LL | | }
1010
LL | | }
1111
| |_^
1212
|
1313
note: the lint level is defined here
14-
--> $DIR/doc-without-codeblock.rs:1:9
14+
--> $DIR/doc-without-codeblock.rs:2:9
1515
|
1616
LL | #![deny(rustdoc::missing_doc_code_examples)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: missing code example in this documentation
20-
--> $DIR/doc-without-codeblock.rs:7:1
20+
--> $DIR/doc-without-codeblock.rs:8:1
2121
|
2222
LL | /// And then, the princess died.
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error: missing code example in this documentation
26-
--> $DIR/doc-without-codeblock.rs:10:5
26+
--> $DIR/doc-without-codeblock.rs:11:5
2727
|
2828
LL | /// Or maybe not because she saved herself!
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error: missing code example in this documentation
32-
--> $DIR/doc-without-codeblock.rs:3:1
32+
--> $DIR/doc-without-codeblock.rs:4:1
3333
|
3434
LL | /// Some docs.
3535
| ^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![deny(unknown_lints)]
2+
//~^ NOTE defined here
3+
4+
#![allow(rustdoc::missing_doc_code_examples)]
5+
//~^ ERROR unknown lint
6+
//~| ERROR unknown lint
7+
//~| NOTE lint is unstable
8+
//~| NOTE lint is unstable
9+
//~| NOTE see issue
10+
//~| NOTE see issue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: unknown lint: `rustdoc::missing_doc_code_examples`
2+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
3+
|
4+
LL | #![allow(rustdoc::missing_doc_code_examples)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:1:9
9+
|
10+
LL | #![deny(unknown_lints)]
11+
| ^^^^^^^^^^^^^
12+
= note: the `rustdoc::missing_doc_code_examples` lint is unstable
13+
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
14+
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
15+
16+
error: unknown lint: `rustdoc::missing_doc_code_examples`
17+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
18+
|
19+
LL | #![allow(rustdoc::missing_doc_code_examples)]
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: the `rustdoc::missing_doc_code_examples` lint is unstable
23+
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
24+
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
25+
26+
error: Compilation failed, aborting rustdoc
27+
28+
error: aborting due to 3 previous errors
29+

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(rustdoc_missing_doc_code_examples)]
2+
13
//! Documenting the kinds of lints emitted by rustdoc.
24
//!
35
//! ```

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error: missing code example in this documentation
2-
--> $DIR/lint-group.rs:16:1
2+
--> $DIR/lint-group.rs:18:1
33
|
44
LL | /// wait, this doesn't have a doctest?
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/lint-group.rs:7:9
8+
--> $DIR/lint-group.rs:9:9
99
|
1010
LL | #![deny(rustdoc::all)]
1111
| ^^^^^^^^^^^^
1212
= note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc::all)]`
1313

1414
error: documentation test in private item
15-
--> $DIR/lint-group.rs:19:1
15+
--> $DIR/lint-group.rs:21:1
1616
|
1717
LL | / /// wait, this *does* have a doctest?
1818
LL | | ///
@@ -24,13 +24,13 @@ LL | | /// ```
2424
= note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc::all)]`
2525

2626
error: missing code example in this documentation
27-
--> $DIR/lint-group.rs:26:1
27+
--> $DIR/lint-group.rs:28:1
2828
|
2929
LL | /// <unknown>
3030
| ^^^^^^^^^^^^^
3131

3232
error: unresolved link to `error`
33-
--> $DIR/lint-group.rs:9:29
33+
--> $DIR/lint-group.rs:11:29
3434
|
3535
LL | /// what up, let's make an [error]
3636
| ^^^^^ no item named `error` in scope
@@ -39,7 +39,7 @@ LL | /// what up, let's make an [error]
3939
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
4040

4141
error: unclosed HTML tag `unknown`
42-
--> $DIR/lint-group.rs:26:5
42+
--> $DIR/lint-group.rs:28:5
4343
|
4444
LL | /// <unknown>
4545
| ^^^^^^^^^

src/test/rustdoc-ui/lint-missing-doc-code-example.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(rustdoc_missing_doc_code_examples)]
12
#![deny(missing_docs)]
23
#![deny(rustdoc::missing_doc_code_examples)]
34

0 commit comments

Comments
 (0)