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 +