public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] hir: improve doc attribute handling ...
@ 2022-06-08 12:33 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:33 UTC (permalink / raw)
To: gcc-cvs
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 {};
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:33 [gcc/devel/rust/master] hir: improve doc attribute handling Thomas Schwinge
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).