From 7189c05bf8fe5b9d21815c44540d76301c90a8aa Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 13 Mar 2021 13:25:27 -0800 Subject: [PATCH] Lint non-meta doc attributes E.g., `#[doc(123)]`. --- compiler/rustc_passes/src/check_attr.rs | 10 ++++++++++ src/test/ui/attributes/doc-attr.rs | 8 ++++++++ src/test/ui/attributes/doc-attr.stderr | 20 +++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index a045b0d596d..5120edb2e35 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -605,6 +605,16 @@ impl CheckAttrVisitor<'tcx> { return false; } } + } else { + self.tcx.struct_span_lint_hir( + INVALID_DOC_ATTRIBUTES, + hir_id, + meta.span(), + |lint| { + lint.build(&format!("unknown `doc` attribute")).emit(); + }, + ); + return false; } } } diff --git a/src/test/ui/attributes/doc-attr.rs b/src/test/ui/attributes/doc-attr.rs index 3a584112973..261ba75dfcb 100644 --- a/src/test/ui/attributes/doc-attr.rs +++ b/src/test/ui/attributes/doc-attr.rs @@ -8,3 +8,11 @@ //~^ ERROR unknown `doc` attribute //~^^ WARN pub fn foo() {} + +#[doc(123)] +//~^ ERROR unknown `doc` attribute +//~| WARN +#[doc("hello", "bar")] +//~^ ERROR unknown `doc` attribute +//~| WARN +fn bar() {} diff --git a/src/test/ui/attributes/doc-attr.stderr b/src/test/ui/attributes/doc-attr.stderr index 21479d25fc2..6bff40a7f70 100644 --- a/src/test/ui/attributes/doc-attr.stderr +++ b/src/test/ui/attributes/doc-attr.stderr @@ -13,6 +13,24 @@ LL | #![deny(warnings)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #82730 +error: unknown `doc` attribute + --> $DIR/doc-attr.rs:12:7 + | +LL | #[doc(123)] + | ^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82730 + +error: unknown `doc` attribute + --> $DIR/doc-attr.rs:15:7 + | +LL | #[doc("hello", "bar")] + | ^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82730 + error: unknown `doc` attribute `as_ptr` --> $DIR/doc-attr.rs:3:8 | @@ -22,5 +40,5 @@ LL | #![doc(as_ptr)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #82730 -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors