Skip to content

Commit ff3b5c5

Browse files
Strenghten checks for doc(auto_cfg(show/hide)) attributes
1 parent 4988b79 commit ff3b5c5

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

compiler/rustc_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ passes_doc_auto_cfg_expects_hide_or_show =
151151
passes_doc_auto_cfg_hide_show_expects_list =
152152
`#![doc(auto_cfg({$attr_name}(...)))]` only expects a list of items
153153
154+
passes_doc_auto_cfg_hide_show_unexpected_item =
155+
`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/values items
156+
154157
passes_doc_auto_cfg_wrong_literal =
155158
`expected boolean for #[doc(auto_cfg = ...)]`
156159

compiler/rustc_passes/src/check_attr.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,20 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11341134
meta.span,
11351135
errors::DocAutoCfgExpectsHideOrShow,
11361136
);
1137-
} else if item.meta_item_list().is_none() {
1137+
} else if let Some(list) = item.meta_item_list() {
1138+
for item in list {
1139+
if item.meta_item_list().is_some() {
1140+
self.tcx.emit_node_span_lint(
1141+
INVALID_DOC_ATTRIBUTES,
1142+
hir_id,
1143+
item.span(),
1144+
errors::DocAutoCfgHideShowUnexpectedItem {
1145+
attr_name: attr_name.as_str(),
1146+
},
1147+
);
1148+
}
1149+
}
1150+
} else {
11381151
self.tcx.emit_node_span_lint(
11391152
INVALID_DOC_ATTRIBUTES,
11401153
hir_id,

compiler/rustc_passes/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ pub(crate) struct DocAutoCfgHideShowExpectsList<'a> {
301301
pub attr_name: &'a str,
302302
}
303303

304+
#[derive(LintDiagnostic)]
305+
#[diag(passes_doc_auto_cfg_hide_show_unexpected_item)]
306+
pub(crate) struct DocAutoCfgHideShowUnexpectedItem<'a> {
307+
pub attr_name: &'a str,
308+
}
309+
304310
#[derive(LintDiagnostic)]
305311
#[diag(passes_doc_test_unknown_any)]
306312
pub(crate) struct DocTestUnknownAny {

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#![cfg_attr(
7979
not(bootstrap),
8080
doc(auto_cfg(hide(
81-
test,
8281
no_global_oom_handling,
8382
no_rc,
8483
no_sync,

library/std/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,7 @@
243243
not(no_global_oom_handling)
244244
))
245245
)]
246-
#![cfg_attr(
247-
not(bootstrap),
248-
doc(auto_cfg(hide(
249-
test,
250-
no_global_oom_handling,
251-
)))
252-
)]
246+
#![cfg_attr(not(bootstrap), doc(auto_cfg(hide(no_global_oom_handling))))]
253247
// Don't link to std. We are std.
254248
#![no_std]
255249
// Tell the compiler to link to either panic_abort or panic_unwind
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#![doc(auto_cfg(hide = "test"))] //~ ERROR
22
#![doc(auto_cfg(hide))] //~ ERROR
3+
#![doc(auto_cfg(hide(not(windows))))] //~ ERROR

tests/rustdoc-ui/lints/doc_cfg_hide.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ error: `#![doc(auto_cfg(hide(...)))]` only expects a list of items
1212
LL | #![doc(auto_cfg(hide))]
1313
| ^^^^^^^^^^^^^^
1414

15-
error: aborting due to 2 previous errors
15+
error: `#![doc(auto_cfg(hide(...)))]` only accepts identifiers or key/values items
16+
--> $DIR/doc_cfg_hide.rs:3:22
17+
|
18+
LL | #![doc(auto_cfg(hide(not(windows))))]
19+
| ^^^^^^^^^^^^
20+
21+
error: aborting due to 3 previous errors
1622

0 commit comments

Comments
 (0)