From 8b576d553678688ece127b6f6a25b611e8726c05 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sat, 24 Feb 2024 08:14:38 -0500 Subject: [PATCH] fix attribute validation on associated items in traits --- compiler/rustc_ast_passes/src/ast_validation.rs | 1 + .../validation-on-associated-items-issue-121537.rs | 7 +++++++ .../validation-on-associated-items-issue-121537.stderr | 8 ++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/ui/attributes/validation-on-associated-items-issue-121537.rs create mode 100644 tests/ui/attributes/validation-on-associated-items-issue-121537.stderr diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 8c9ad83608761..3330b2c061175 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1519,6 +1519,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { generics, body.as_deref(), ); + walk_list!(self, visit_attribute, &item.attrs); self.visit_fn(kind, item.span, item.id); } AssocItemKind::Type(_) => { diff --git a/tests/ui/attributes/validation-on-associated-items-issue-121537.rs b/tests/ui/attributes/validation-on-associated-items-issue-121537.rs new file mode 100644 index 0000000000000..60e5a21eec774 --- /dev/null +++ b/tests/ui/attributes/validation-on-associated-items-issue-121537.rs @@ -0,0 +1,7 @@ +trait MyTrait { + #[doc = MyTrait] + //~^ ERROR attribute value must be a literal + fn myfun(); +} + +fn main() {} diff --git a/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr new file mode 100644 index 0000000000000..9c37bb8231790 --- /dev/null +++ b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr @@ -0,0 +1,8 @@ +error: attribute value must be a literal + --> $DIR/validation-on-associated-items-issue-121537.rs:2:13 + | +LL | #[doc = MyTrait] + | ^^^^^^^ + +error: aborting due to 1 previous error +