Skip to content

Warn about unknown doc attributes #82662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-ui/doc-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![crate_type = "lib"]
#![doc(as_ptr)] //~ ERROR

#[doc(as_ptr)] //~ ERROR
pub fn foo() {}
14 changes: 14 additions & 0 deletions src/test/rustdoc-ui/doc-attr.stderr
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions src/test/ui/attributes/doc-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![crate_type = "lib"]
#![doc(as_ptr)] //~ ERROR

#[doc(as_ptr)] //~ ERROR
pub fn foo() {}
14 changes: 14 additions & 0 deletions src/test/ui/attributes/doc-attr.stderr
Original file line number Diff line number Diff line change
@@ -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