diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-09-13 22:25:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-13 22:25:35 +0200 |
| commit | 8fa8021451162bdc253c1ee781bc28d94980e5bf (patch) | |
| tree | f9e9cd51a5e2a8a6c8993f01d79bf2f792173835 | |
| parent | f80b38b5689165cfcd013af1051e0914a608487b (diff) | |
| parent | c4559ebfde5d6cae587d4f099d758c1d7c74998f (diff) | |
| download | rust-8fa8021451162bdc253c1ee781bc28d94980e5bf.tar.gz rust-8fa8021451162bdc253c1ee781bc28d94980e5bf.zip | |
Rollup merge of #101752 - GuillaumeGomez:improve-attr-docs, r=lqd
Improve Attribute doc methods r? `@lqd`
| -rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index a40508494cd..28198e69bff 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -232,7 +232,8 @@ impl AttrItem { impl Attribute { /// Returns `true` if it is a sugared doc comment (`///` or `//!` for example). - /// So `#[doc = "doc"]` will return `false`. + /// So `#[doc = "doc"]` (which is a doc comment) and `#[doc(...)]` (which is not + /// a doc comment) will return `false`. pub fn is_doc_comment(&self) -> bool { match self.kind { AttrKind::Normal(..) => false, @@ -240,6 +241,11 @@ impl Attribute { } } + /// Returns the documentation and its kind if this is a doc comment or a sugared doc comment. + /// * `///doc` returns `Some(("doc", CommentKind::Line))`. + /// * `/** doc */` returns `Some(("doc", CommentKind::Block))`. + /// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`. + /// * `#[doc(...)]` returns `None`. pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> { match self.kind { AttrKind::DocComment(kind, data) => Some((data, kind)), @@ -252,6 +258,10 @@ impl Attribute { } } + /// Returns the documentation if this is a doc comment or a sugared doc comment. + /// * `///doc` returns `Some("doc")`. + /// * `#[doc = "doc"]` returns `Some("doc")`. + /// * `#[doc(...)]` returns `None`. pub fn doc_str(&self) -> Option<Symbol> { match self.kind { AttrKind::DocComment(.., data) => Some(data), |
