Rollup merge of #82662 - GuillaumeGomez:doc-attr-check, r=jyn514

Warn about unknown doc attributes

Fixes #82652.

For the text error, I decided to go for "invalid" instead of "unknown". What do you think?

r? `@jyn514`
This commit is contained in:
Guillaume Gomez 2021-03-02 00:50:10 +01:00 committed by GitHub
commit 0c6b69aa70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 0 deletions

View File

@ -544,6 +544,41 @@ impl CheckAttrVisitor<'tcx> {
{
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::primitive,
sym::spotlight,
sym::test,
]
.iter()
.any(|m| i_meta.has_name(*m))
{
self.tcx
.sess
.struct_span_err(
meta.span(),
&format!(
"unknown `doc` attribute `{}`",
i_meta.name_or_empty(),
),
)
.emit();
return false;
}
}
}
}

View File

@ -0,0 +1,5 @@
#![crate_type = "lib"]
#![doc(as_ptr)] //~ ERROR
#[doc(as_ptr)] //~ ERROR
pub fn foo() {}

View File

@ -0,0 +1,14 @@
error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:4:7
|
LL | #[doc(as_ptr)]
| ^^^^^^
error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:2:8
|
LL | #![doc(as_ptr)]
| ^^^^^^
error: aborting due to 2 previous errors

View File

@ -0,0 +1,5 @@
#![crate_type = "lib"]
#![doc(as_ptr)] //~ ERROR
#[doc(as_ptr)] //~ ERROR
pub fn foo() {}

View File

@ -0,0 +1,14 @@
error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:4:7
|
LL | #[doc(as_ptr)]
| ^^^^^^
error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:2:8
|
LL | #![doc(as_ptr)]
| ^^^^^^
error: aborting due to 2 previous errors