Skip to content

Commit f528414

Browse files
Add missing checks for doc(cfg_hide(...)) attribute
1 parent 1755c85 commit f528414

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Diff for: compiler/rustc_error_messages/locales/en-US/passes.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ passes_doc_test_takes_list =
145145
passes_doc_primitive =
146146
`doc(primitive)` should never have been stable
147147
148+
passes_doc_cfg_hide_takes_list =
149+
`#[doc(cfg_hide(...)]` takes a list of attributes
150+
148151
passes_doc_test_unknown_any =
149152
unknown `doc` attribute `{$path}`
150153

Diff for: compiler/rustc_passes/src/check_attr.rs

+23
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,22 @@ impl CheckAttrVisitor<'_> {
934934
is_valid
935935
}
936936

937+
/// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes.
938+
/// Returns `true` if valid.
939+
fn check_doc_cfg_hide(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
940+
if meta.meta_item_list().is_some() {
941+
true
942+
} else {
943+
self.tcx.emit_spanned_lint(
944+
INVALID_DOC_ATTRIBUTES,
945+
hir_id,
946+
meta.span(),
947+
errors::DocCfgHideTakesList,
948+
);
949+
false
950+
}
951+
}
952+
937953
/// Runs various checks on `#[doc]` attributes. Returns `true` if valid.
938954
///
939955
/// `specified_inline` should be initialized to `None` and kept for the scope
@@ -987,6 +1003,13 @@ impl CheckAttrVisitor<'_> {
9871003
is_valid = false;
9881004
}
9891005

1006+
sym::cfg_hide
1007+
if !self.check_attr_crate_level(attr, meta, hir_id)
1008+
|| !self.check_doc_cfg_hide(meta, hir_id) =>
1009+
{
1010+
is_valid = false;
1011+
}
1012+
9901013
sym::inline | sym::no_inline
9911014
if !self.check_doc_inline(
9921015
attr,

Diff for: compiler/rustc_passes/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ pub struct DocTestUnknown {
271271
#[diag(passes::doc_test_takes_list)]
272272
pub struct DocTestTakesList;
273273

274+
#[derive(LintDiagnostic)]
275+
#[diag(passes::doc_cfg_hide_takes_list)]
276+
pub struct DocCfgHideTakesList;
277+
274278
#[derive(LintDiagnostic)]
275279
#[diag(passes::doc_primitive)]
276280
pub struct DocPrimitive;

0 commit comments

Comments
 (0)