Strenghten checks for doc(auto_cfg(show/hide)) attributes

This commit is contained in:
Guillaume Gomez
2025-04-01 17:24:28 +02:00
parent 2d82c99f1e
commit 63aefe0737
7 changed files with 32 additions and 10 deletions
+3
View File
@@ -149,6 +149,9 @@ passes_doc_auto_cfg_expects_hide_or_show =
passes_doc_auto_cfg_hide_show_expects_list =
`#![doc(auto_cfg({$attr_name}(...)))]` only expects a list of items
passes_doc_auto_cfg_hide_show_unexpected_item =
`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/values items
passes_doc_auto_cfg_wrong_literal =
`expected boolean for #[doc(auto_cfg = ...)]`
+14 -1
View File
@@ -1187,7 +1187,20 @@ fn check_doc_auto_cfg(&self, meta: &MetaItemInner, hir_id: HirId) {
meta.span,
errors::DocAutoCfgExpectsHideOrShow,
);
} else if item.meta_item_list().is_none() {
} else if let Some(list) = item.meta_item_list() {
for item in list {
if item.meta_item_list().is_some() {
self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
item.span(),
errors::DocAutoCfgHideShowUnexpectedItem {
attr_name: attr_name.as_str(),
},
);
}
}
} else {
self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
+6
View File
@@ -322,6 +322,12 @@ pub(crate) struct DocAutoCfgHideShowExpectsList<'a> {
pub attr_name: &'a str,
}
#[derive(LintDiagnostic)]
#[diag(passes_doc_auto_cfg_hide_show_unexpected_item)]
pub(crate) struct DocAutoCfgHideShowUnexpectedItem<'a> {
pub attr_name: &'a str,
}
#[derive(LintDiagnostic)]
#[diag(passes_doc_test_unknown_any)]
pub(crate) struct DocTestUnknownAny {
-1
View File
@@ -78,7 +78,6 @@
#![cfg_attr(
not(bootstrap),
doc(auto_cfg(hide(
test,
no_global_oom_handling,
no_rc,
no_sync,
+1 -7
View File
@@ -243,13 +243,7 @@
not(no_global_oom_handling)
))
)]
#![cfg_attr(
not(bootstrap),
doc(auto_cfg(hide(
test,
no_global_oom_handling,
)))
)]
#![cfg_attr(not(bootstrap), doc(auto_cfg(hide(no_global_oom_handling))))]
// Don't link to std. We are std.
#![no_std]
// Tell the compiler to link to either panic_abort or panic_unwind
+1
View File
@@ -1,2 +1,3 @@
#![doc(auto_cfg(hide = "test"))] //~ ERROR
#![doc(auto_cfg(hide))] //~ ERROR
#![doc(auto_cfg(hide(not(windows))))] //~ ERROR
+7 -1
View File
@@ -12,5 +12,11 @@ error: `#![doc(auto_cfg(hide(...)))]` only expects a list of items
LL | #![doc(auto_cfg(hide))]
| ^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: `#![doc(auto_cfg(hide(...)))]` only accepts identifiers or key/values items
--> $DIR/doc_cfg_hide.rs:3:22
|
LL | #![doc(auto_cfg(hide(not(windows))))]
| ^^^^^^^^^^^^
error: aborting due to 3 previous errors