Skip to content

Commit 7189c05

Browse files
committed
Lint non-meta doc attributes
E.g., `#[doc(123)]`.
1 parent 9613a88 commit 7189c05

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,16 @@ impl CheckAttrVisitor<'tcx> {
605605
return false;
606606
}
607607
}
608+
} else {
609+
self.tcx.struct_span_lint_hir(
610+
INVALID_DOC_ATTRIBUTES,
611+
hir_id,
612+
meta.span(),
613+
|lint| {
614+
lint.build(&format!("unknown `doc` attribute")).emit();
615+
},
616+
);
617+
return false;
608618
}
609619
}
610620
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88
//~^ ERROR unknown `doc` attribute
99
//~^^ WARN
1010
pub fn foo() {}
11+
12+
#[doc(123)]
13+
//~^ ERROR unknown `doc` attribute
14+
//~| WARN
15+
#[doc("hello", "bar")]
16+
//~^ ERROR unknown `doc` attribute
17+
//~| WARN
18+
fn bar() {}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ LL | #![deny(warnings)]
1313
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1414
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
1515

16+
error: unknown `doc` attribute
17+
--> $DIR/doc-attr.rs:12:7
18+
|
19+
LL | #[doc(123)]
20+
| ^^^
21+
|
22+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
24+
25+
error: unknown `doc` attribute
26+
--> $DIR/doc-attr.rs:15:7
27+
|
28+
LL | #[doc("hello", "bar")]
29+
| ^^^^^^^
30+
|
31+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
32+
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
33+
1634
error: unknown `doc` attribute `as_ptr`
1735
--> $DIR/doc-attr.rs:3:8
1836
|
@@ -22,5 +40,5 @@ LL | #![doc(as_ptr)]
2240
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2341
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
2442

25-
error: aborting due to 2 previous errors
43+
error: aborting due to 4 previous errors
2644

0 commit comments

Comments
 (0)