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