Skip to content

Commit 071b9de

Browse files
authored
Rollup merge of rust-lang#147991 - GuillaumeGomez:check-doc-cfg-private-hidden, r=fmease
[rustdoc] Check `doc(cfg())` even of private/hidden items Fixes regression found out by `@fmease` [here](rust-lang#138907 (comment)). In short: the pass which checks the `doc(cfg())` attributes needed to be moved before the private/hidden stripping items passes.
2 parents fc0370a + e1e851d commit 071b9de

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

src/librustdoc/passes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
9595
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
9696
ConditionalPass::always(CHECK_DOC_CFG),
9797
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
98+
ConditionalPass::always(PROPAGATE_DOC_CFG),
9899
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
99100
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
100101
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
101102
ConditionalPass::always(COLLECT_INTRA_DOC_LINKS),
102-
ConditionalPass::always(PROPAGATE_DOC_CFG),
103103
ConditionalPass::always(PROPAGATE_STABILITY),
104104
ConditionalPass::always(RUN_LINTS),
105105
];

tests/rustdoc-ui/invalid-cfg.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,20 @@
22
#[doc(cfg = "x")] //~ ERROR not followed by parentheses
33
#[doc(cfg(x, y))] //~ ERROR multiple `cfg` predicates
44
pub struct S {}
5+
6+
// We check it also fails on private items.
7+
#[doc(cfg = "x")] //~ ERROR not followed by parentheses
8+
#[doc(cfg(x, y))] //~ ERROR multiple `cfg` predicates
9+
struct X {}
10+
11+
// We check it also fails on hidden items.
12+
#[doc(cfg = "x")] //~ ERROR not followed by parentheses
13+
#[doc(cfg(x, y))] //~ ERROR multiple `cfg` predicates
14+
#[doc(hidden)]
15+
pub struct Y {}
16+
17+
// We check it also fails on hidden AND private items.
18+
#[doc(cfg = "x")] //~ ERROR not followed by parentheses
19+
#[doc(cfg(x, y))] //~ ERROR multiple `cfg` predicates
20+
#[doc(hidden)]
21+
struct Z {}

tests/rustdoc-ui/invalid-cfg.stderr

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,41 @@ error: multiple `cfg` predicates are specified
1010
LL | #[doc(cfg(x, y))]
1111
| ^
1212

13-
error: aborting due to 2 previous errors
13+
error: `cfg` is not followed by parentheses
14+
--> $DIR/invalid-cfg.rs:7:7
15+
|
16+
LL | #[doc(cfg = "x")]
17+
| ^^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
18+
19+
error: multiple `cfg` predicates are specified
20+
--> $DIR/invalid-cfg.rs:8:14
21+
|
22+
LL | #[doc(cfg(x, y))]
23+
| ^
24+
25+
error: `cfg` is not followed by parentheses
26+
--> $DIR/invalid-cfg.rs:12:7
27+
|
28+
LL | #[doc(cfg = "x")]
29+
| ^^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
30+
31+
error: multiple `cfg` predicates are specified
32+
--> $DIR/invalid-cfg.rs:13:14
33+
|
34+
LL | #[doc(cfg(x, y))]
35+
| ^
36+
37+
error: `cfg` is not followed by parentheses
38+
--> $DIR/invalid-cfg.rs:18:7
39+
|
40+
LL | #[doc(cfg = "x")]
41+
| ^^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
42+
43+
error: multiple `cfg` predicates are specified
44+
--> $DIR/invalid-cfg.rs:19:14
45+
|
46+
LL | #[doc(cfg(x, y))]
47+
| ^
48+
49+
error: aborting due to 8 previous errors
1450

tests/rustdoc-ui/issues/issue-91713.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Default passes for rustdoc:
1717
check_doc_test_visibility
1818
check-doc-cfg
1919
strip-aliased-non-local
20+
propagate-doc-cfg
2021
strip-hidden (when not --document-hidden-items)
2122
strip-private (when not --document-private-items)
2223
strip-priv-imports (when --document-private-items)
2324
collect-intra-doc-links
24-
propagate-doc-cfg
2525
propagate-stability
2626
run-lints
2727

0 commit comments

Comments
 (0)