public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] hir: improve doc attribute handling ...
Date: Wed, 8 Jun 2022 12:33:33 +0000 (GMT) [thread overview]
Message-ID: <20220608123333.C4569388879D@sourceware.org> (raw)
https://gcc.gnu.org/g:a1c34b478fee1c1415b65624ad647cf3b93c9090
commit a1c34b478fee1c1415b65624ad647cf3b93c9090
Author: liushuyu <liushuyu011@gmail.com>
Date: Tue Apr 19 20:49:35 2022 -0600
hir: improve doc attribute handling ...
... should fix #1125
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
Diff:
---
gcc/rust/hir/rust-ast-lower-base.cc | 27 ++++++++++++++++++++++-
gcc/rust/hir/rust-ast-lower-base.h | 3 +++
gcc/rust/util/rust-attributes.cc | 9 ++++----
| 16 ++++++++++++++
4 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index fa7c700bda0..85960ef207a 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -838,7 +838,11 @@ ASTLoweringBase::handle_outer_attributes (const HIR::Item &item)
&& attr.get_attr_input ().get_attr_input_type ()
== AST::AttrInput::AttrInputType::LITERAL;
- if (is_lang_item)
+ bool is_doc_item = str_path.compare ("doc") == 0;
+
+ if (is_doc_item)
+ handle_doc_item_attribute (item, attr);
+ else if (is_lang_item)
handle_lang_item_attribute (item, attr);
else if (!attribute_handled_in_another_pass (str_path))
{
@@ -848,6 +852,27 @@ ASTLoweringBase::handle_outer_attributes (const HIR::Item &item)
}
}
+void
+ASTLoweringBase::handle_doc_item_attribute (const HIR::Item &item,
+ 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 (simple_doc_comment)
+ return;
+
+ const AST::AttrInput &input = attr.get_attr_input ();
+ bool is_token_tree
+ = input.get_attr_input_type () == AST::AttrInput::AttrInputType::TOKEN_TREE;
+ rust_assert (is_token_tree);
+ const auto &option = static_cast<const AST::DelimTokenTree &> (input);
+ AST::AttrInputMetaItemContainer *meta_item = option.parse_to_meta_item ();
+
+ // TODO: add actual and complete checks for the doc attributes
+ rust_assert (meta_item);
+}
+
void
ASTLoweringBase::handle_lang_item_attribute (const HIR::Item &item,
const AST::Attribute &attr)
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index 185f4672499..c61d700cfb0 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -268,6 +268,9 @@ protected:
void handle_lang_item_attribute (const HIR::Item &item,
const AST::Attribute &attr);
+ void handle_doc_item_attribute (const HIR::Item &item,
+ const AST::Attribute &attr);
+
bool is_known_attribute (const std::string &attribute_path) const;
bool
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 4f3bd0b3649..b1211fe792c 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -21,11 +21,12 @@
namespace Rust {
namespace Analysis {
-// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#256
+// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248
static const BuiltinAttrDefinition __definitions[]
- = {{"inline", CODE_GENERATION}, {"cfg", EXPANSION},
- {"cfg_attr", EXPANSION}, {"allow", STATIC_ANALYSIS},
- {"lang", HIR_LOWERING}, {"must_use", STATIC_ANALYSIS}};
+ = {{"inline", CODE_GENERATION}, {"cfg", EXPANSION},
+ {"cfg_attr", EXPANSION}, {"allow", STATIC_ANALYSIS},
+ {"doc", HIR_LOWERING}, {"lang", HIR_LOWERING},
+ {"must_use", STATIC_ANALYSIS}};
BuiltinAttributeMappings *
BuiltinAttributeMappings::get ()
--git a/gcc/testsuite/rust/compile/torture/doc_comment.rs b/gcc/testsuite/rust/compile/torture/doc_comment.rs
new file mode 100644
index 00000000000..f99e41524ae
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/doc_comment.rs
@@ -0,0 +1,16 @@
+/// doc comment 1
+/// doc comment 2
+/// `blah blah` markdown
+pub struct TestStruct {}
+
+#[doc(hidden)]
+pub struct DocAttribute {}
+
+#[doc(a,b)]
+pub struct UnkAttribute {}
+
+fn main() {
+ let _ = TestStruct {};
+ let _ = DocAttribute {};
+ let _ = UnkAttribute {};
+}
reply other threads:[~2022-06-08 12:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220608123333.C4569388879D@sourceware.org \
--to=tschwinge@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).