Skip to content

Commit 0c6b69a

Browse files
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`
2 parents d259d1d + f6de130 commit 0c6b69a

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

compiler/rustc_passes/src/check_attr.rs

+35
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,41 @@ impl CheckAttrVisitor<'tcx> {
544544
{
545545
return false;
546546
}
547+
} else if let Some(i_meta) = meta.meta_item() {
548+
if ![
549+
sym::cfg,
550+
sym::hidden,
551+
sym::html_favicon_url,
552+
sym::html_logo_url,
553+
sym::html_no_source,
554+
sym::html_playground_url,
555+
sym::html_root_url,
556+
sym::include,
557+
sym::inline,
558+
sym::issue_tracker_base_url,
559+
sym::masked,
560+
sym::no_default_passes, // deprecated
561+
sym::no_inline,
562+
sym::passes, // deprecated
563+
sym::primitive,
564+
sym::spotlight,
565+
sym::test,
566+
]
567+
.iter()
568+
.any(|m| i_meta.has_name(*m))
569+
{
570+
self.tcx
571+
.sess
572+
.struct_span_err(
573+
meta.span(),
574+
&format!(
575+
"unknown `doc` attribute `{}`",
576+
i_meta.name_or_empty(),
577+
),
578+
)
579+
.emit();
580+
return false;
581+
}
547582
}
548583
}
549584
}

src/test/rustdoc-ui/doc-attr.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![crate_type = "lib"]
2+
#![doc(as_ptr)] //~ ERROR
3+
4+
#[doc(as_ptr)] //~ ERROR
5+
pub fn foo() {}

src/test/rustdoc-ui/doc-attr.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unknown `doc` attribute `as_ptr`
2+
--> $DIR/doc-attr.rs:4:7
3+
|
4+
LL | #[doc(as_ptr)]
5+
| ^^^^^^
6+
7+
error: unknown `doc` attribute `as_ptr`
8+
--> $DIR/doc-attr.rs:2:8
9+
|
10+
LL | #![doc(as_ptr)]
11+
| ^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

src/test/ui/attributes/doc-attr.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![crate_type = "lib"]
2+
#![doc(as_ptr)] //~ ERROR
3+
4+
#[doc(as_ptr)] //~ ERROR
5+
pub fn foo() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unknown `doc` attribute `as_ptr`
2+
--> $DIR/doc-attr.rs:4:7
3+
|
4+
LL | #[doc(as_ptr)]
5+
| ^^^^^^
6+
7+
error: unknown `doc` attribute `as_ptr`
8+
--> $DIR/doc-attr.rs:2:8
9+
|
10+
LL | #![doc(as_ptr)]
11+
| ^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)