From: Lucas Ly Ba <[email protected]>
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::handle_doc_item_attribute): Make error.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4226.rs: New test.
Signed-off-by: Lucas Ly Ba <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/rust-GCC/gccrs/commit/6e5929aea5eb223459ad691398ec7239f4babe7b
gcc/rust/hir/rust-ast-lower-base.cc | 14 +++++++++++---
gcc/testsuite/rust/compile/issue-4226.rs | 3 +++
2 files changed, 14 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4226.rs
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc
b/gcc/rust/hir/rust-ast-lower-base.cc
index 1c8e5b6d2..8984c98da 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -820,9 +820,17 @@ void
ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &,
const AST::Attribute &attr)
{
- auto simple_doc_comment = attr.has_attr_input ()
- && attr.get_attr_input ().get_attr_input_type ()
- == AST::AttrInput::AttrInputType::LITERAL;
+ if (!attr.has_attr_input ())
+ {
+ rust_error_at (attr.get_locus (),
+ "attribute must be of the form %qs or %qs",
+ "#[doc(hidden|inline|...)]", "#[doc = string]");
+ return;
+ }
+
+ auto simple_doc_comment = attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL;
+
if (simple_doc_comment)
return;
diff --git a/gcc/testsuite/rust/compile/issue-4226.rs
b/gcc/testsuite/rust/compile/issue-4226.rs
new file mode 100644
index 000000000..553faf291
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4226.rs
@@ -0,0 +1,3 @@
+#[doc]
+// { dg-error "attribute must be of the form ...doc.hidden.inline....... or
...doc = string.." "" { target *-*-* } .-1 }
+pub fn a(){}
base-commit: c01290e234ba1018aaa88394cb1e095f6a5d99e0
--
2.51.2