From a0a19aa3faf9a2f53f014c07cb31c50d725fe2e0 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 1 Oct 2025 17:56:00 +0200 Subject: [PATCH] gccrs: Add doc attribute checking on traits Doc attribute checking was not performed on traits. gcc/rust/ChangeLog: * util/rust-attributes.cc (check_doc_attribute): Change message. (AttributeChecker::visit): Add doc attribute checking on traits. gcc/testsuite/ChangeLog: * rust/compile/attr_malformed_doc.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-attributes.cc | 5 +++-- gcc/testsuite/rust/compile/attr_malformed_doc.rs | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/attr_malformed_doc.rs diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index ce29e59b06d..e4d787794d4 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -240,8 +240,8 @@ check_doc_attribute (const AST::Attribute &attribute) { rust_error_at ( attribute.get_locus (), - // FIXME: Improve error message here. Rustc has a very good one - "%<#[doc]%> cannot be an empty attribute"); + "valid forms for the attribute are " + "%<#[doc(hidden|inline|...)]%> and %<#[doc = \" string \"]%>"); return; } @@ -826,6 +826,7 @@ void AttributeChecker::visit (AST::Trait &trait) { check_proc_macro_non_function (trait.get_outer_attrs ()); + check_attributes (trait.get_outer_attrs ()); } void diff --git a/gcc/testsuite/rust/compile/attr_malformed_doc.rs b/gcc/testsuite/rust/compile/attr_malformed_doc.rs new file mode 100644 index 00000000000..6b9ef6174df --- /dev/null +++ b/gcc/testsuite/rust/compile/attr_malformed_doc.rs @@ -0,0 +1,3 @@ +// { dg-error "valid forms for the attribute are ...doc.hidden.inline....... and ...doc = . string ..." "" { target *-*-* } .+1 } +#[doc] +trait MyTrait {} -- 2.47.3