1
Fork 0

Refactor check_doc_attrs body

This change makes it easier to follow the control flow.

I also moved the end-of-line comments attached to some symbols to before
the symbol listing. This allows rustfmt to format the code; otherwise no
formatting occurs (see rust-lang/rustfmt#4750).
This commit is contained in:
Camelid 2021-03-13 13:13:27 -08:00
parent 61365c0625
commit 9613a88db5

View file

@ -531,60 +531,65 @@ impl CheckAttrVisitor<'tcx> {
} }
fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool { fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
if let Some(mi) = attr.meta() { if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list().map(|l| l.to_vec())) {
if let Some(list) = mi.meta_item_list() { for meta in list {
for meta in list { if let Some(i_meta) = meta.meta_item() {
if meta.has_name(sym::alias) { match i_meta.name_or_empty() {
if !self.check_attr_crate_level(meta, hir_id, "alias") sym::alias
|| !self.check_doc_alias(meta, hir_id, target) if !self.check_attr_crate_level(&meta, hir_id, "alias")
|| !self.check_doc_alias(&meta, hir_id, target) =>
{ {
return false; return false;
} }
} else if meta.has_name(sym::keyword) {
if !self.check_attr_crate_level(meta, hir_id, "keyword") sym::keyword
|| !self.check_doc_keyword(meta, hir_id) if !self.check_attr_crate_level(&meta, hir_id, "keyword")
|| !self.check_doc_keyword(&meta, hir_id) =>
{ {
return false; return false;
} }
} else if meta.has_name(sym::test) {
if CRATE_HIR_ID != hir_id { sym::test if CRATE_HIR_ID != hir_id => {
self.tcx.struct_span_lint_hir( self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
|lint| { |lint| {
lint.build( lint.build(
"`#![doc(test(...)]` is only allowed as a crate level attribute" "`#![doc(test(...)]` is only allowed \
as a crate level attribute",
) )
.emit(); .emit();
}, },
); );
return false; return false;
} }
} else if let Some(i_meta) = meta.meta_item() {
if ![ // no_default_passes: deprecated
sym::cfg, // passes: deprecated
sym::hidden, // plugins: removed, but rustdoc warns about it itself
sym::html_favicon_url, sym::alias
sym::html_logo_url, | sym::cfg
sym::html_no_source, | sym::hidden
sym::html_playground_url, | sym::html_favicon_url
sym::html_root_url, | sym::html_logo_url
sym::include, | sym::html_no_source
sym::inline, | sym::html_playground_url
sym::issue_tracker_base_url, | sym::html_root_url
sym::masked, | sym::include
sym::no_default_passes, // deprecated | sym::inline
sym::no_inline, | sym::issue_tracker_base_url
sym::passes, // deprecated | sym::keyword
sym::plugins, // removed, but rustdoc warns about it itself | sym::masked
sym::primitive, | sym::no_default_passes
sym::spotlight, | sym::no_inline
sym::test, | sym::passes
] | sym::plugins
.iter() | sym::primitive
.any(|m| i_meta.has_name(*m)) | sym::spotlight
{ | sym::test => {}
_ => {
self.tcx.struct_span_lint_hir( self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,