Skip to content

Commit fbd548a

Browse files
committed
Only include stable lints in rustdoc::all group
Including unstable lints in the lint group produces unintuitive behavior on stable (see #106289). Meanwhile, if we only included unstable lints on nightly and not on stable, we could end up with confusing bugs that were hard to compare across versions of Rust that lacked code changes. I think that only including stable lints in `rustdoc::all`, no matter the release channel, is the most intuitive option. Users can then control unstable lints individually, which is reasonable since they have to enable the feature gates individually anyway.
1 parent 7b55296 commit fbd548a

8 files changed

+45
-20
lines changed

src/librustdoc/lint.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ pub(crate) fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
194194
true,
195195
"rustdoc::all",
196196
Some("rustdoc"),
197-
RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(),
197+
RUSTDOC_LINTS
198+
.iter()
199+
.filter(|lint| lint.feature_gate.is_none()) // only include stable lints
200+
.map(|&lint| LintId::of(lint))
201+
.collect(),
198202
);
199203
for lint in &*RUSTDOC_LINTS {
200204
let name = lint.name_lower();

tests/rustdoc-ui/check-fail.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(rustdoc_missing_doc_code_examples)]
44
#![deny(missing_docs)]
5+
#![deny(rustdoc::missing_doc_code_examples)]
56
#![deny(rustdoc::all)]
67

78
//! ```rust,testharness

tests/rustdoc-ui/check-fail.stderr

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: missing documentation for a function
2-
--> $DIR/check-fail.rs:12:1
2+
--> $DIR/check-fail.rs:13:1
33
|
44
LL | pub fn foo() {}
55
| ^^^^^^^^^^^^
@@ -11,20 +11,19 @@ LL | #![deny(missing_docs)]
1111
| ^^^^^^^^^^^^
1212

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

2625
error: unknown attribute `testharness`. Did you mean `test_harness`?
27-
--> $DIR/check-fail.rs:7:1
26+
--> $DIR/check-fail.rs:8:1
2827
|
2928
LL | / //! ```rust,testharness
3029
LL | |
@@ -33,10 +32,15 @@ LL | | //! ```
3332
| |_______^
3433
|
3534
= 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
35+
note: the lint level is defined here
36+
--> $DIR/check-fail.rs:6:9
37+
|
38+
LL | #![deny(rustdoc::all)]
39+
| ^^^^^^^^^^^^
3640
= note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]`
3741

3842
error: unknown attribute `testharness`. Did you mean `test_harness`?
39-
--> $DIR/check-fail.rs:16:1
43+
--> $DIR/check-fail.rs:17:1
4044
|
4145
LL | / /// hello
4246
LL | |

tests/rustdoc-ui/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//~^^ WARN
88

99
#![warn(missing_docs)]
10+
#![warn(rustdoc::missing_doc_code_examples)]
1011
#![warn(rustdoc::all)]
1112

1213
pub fn foo() {}

tests/rustdoc-ui/check.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | #![warn(missing_docs)]
1717
| ^^^^^^^^^^^^
1818

1919
warning: missing documentation for a function
20-
--> $DIR/check.rs:12:1
20+
--> $DIR/check.rs:13:1
2121
|
2222
LL | pub fn foo() {}
2323
| ^^^^^^^^^^^^
@@ -27,7 +27,7 @@ warning: no documentation found for this crate's top-level module
2727
= help: The following guide may be of use:
2828
https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
2929
note: the lint level is defined here
30-
--> $DIR/check.rs:10:9
30+
--> $DIR/check.rs:11:9
3131
|
3232
LL | #![warn(rustdoc::all)]
3333
| ^^^^^^^^^^^^
@@ -45,10 +45,14 @@ LL | |
4545
LL | | pub fn foo() {}
4646
| |_______________^
4747
|
48-
= note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc::all)]`
48+
note: the lint level is defined here
49+
--> $DIR/check.rs:10:9
50+
|
51+
LL | #![warn(rustdoc::missing_doc_code_examples)]
52+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4953

5054
warning: missing code example in this documentation
51-
--> $DIR/check.rs:12:1
55+
--> $DIR/check.rs:13:1
5256
|
5357
LL | pub fn foo() {}
5458
| ^^^^^^^^^^^^^^^

tests/rustdoc-ui/lint-group.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! println!("sup");
77
//! ```
88
9+
#![deny(rustdoc::missing_doc_code_examples)]
910
#![deny(rustdoc::all)]
1011

1112
/// what up, let's make an [error]

tests/rustdoc-ui/lint-group.stderr

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

1413
error: documentation test in private item
15-
--> $DIR/lint-group.rs:21:1
14+
--> $DIR/lint-group.rs:22:1
1615
|
1716
LL | / /// wait, this *does* have a doctest?
1817
LL | | ///
@@ -21,16 +20,21 @@ LL | | /// println!("sup");
2120
LL | | /// ```
2221
| |_______^
2322
|
23+
note: the lint level is defined here
24+
--> $DIR/lint-group.rs:10:9
25+
|
26+
LL | #![deny(rustdoc::all)]
27+
| ^^^^^^^^^^^^
2428
= note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc::all)]`
2529

2630
error: missing code example in this documentation
27-
--> $DIR/lint-group.rs:28:1
31+
--> $DIR/lint-group.rs:29:1
2832
|
2933
LL | /// <unknown>
3034
| ^^^^^^^^^^^^^
3135

3236
error: unresolved link to `error`
33-
--> $DIR/lint-group.rs:11:29
37+
--> $DIR/lint-group.rs:12:29
3438
|
3539
LL | /// what up, let's make an [error]
3640
| ^^^^^ no item named `error` in scope
@@ -39,7 +43,7 @@ LL | /// what up, let's make an [error]
3943
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc::all)]`
4044

4145
error: unclosed HTML tag `unknown`
42-
--> $DIR/lint-group.rs:28:5
46+
--> $DIR/lint-group.rs:29:5
4347
|
4448
LL | /// <unknown>
4549
| ^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-pass
2+
3+
// Ensure `rustdoc::all` only affects stable lints. See #106289.
4+
5+
#![deny(unknown_lints)]
6+
#![allow(rustdoc::all)]

0 commit comments

Comments
 (0)