mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Strenghten checks for doc(auto_cfg(show/hide)) attributes
This commit is contained in:
@@ -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 = ...)]`
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -78,7 +78,6 @@
|
||||
#![cfg_attr(
|
||||
not(bootstrap),
|
||||
doc(auto_cfg(hide(
|
||||
test,
|
||||
no_global_oom_handling,
|
||||
no_rc,
|
||||
no_sync,
|
||||
|
||||
@@ -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,2 +1,3 @@
|
||||
#![doc(auto_cfg(hide = "test"))] //~ ERROR
|
||||
#![doc(auto_cfg(hide))] //~ ERROR
|
||||
#![doc(auto_cfg(hide(not(windows))))] //~ ERROR
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user