]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add doc attribute checking on traits
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 1 Oct 2025 15:56:00 +0000 (17:56 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 20:30:55 +0000 (21:30 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/attr_malformed_doc.rs [new file with mode: 0644]

index ce29e59b06da917e916b42659e3aebb0784d9de5..e4d787794d4b20115dd8aa3fdfc15fb07a9114b5 100644 (file)
@@ -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 (file)
index 0000000..6b9ef61
--- /dev/null
@@ -0,0 +1,3 @@
+// { dg-error "valid forms for the attribute are ...doc.hidden.inline....... and ...doc = . string ..." "" { target *-*-* } .+1 }
+#[doc]
+trait MyTrait {}