diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-11-05 16:15:45 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-11-05 16:38:15 +0100 |
| commit | 33009601afefcd79cd500b12ccc1b3ab5eda11f1 (patch) | |
| tree | a4d2e6fff5d52eac7d59a0929bc248c40656edec | |
| parent | 096277e989d6de11c3077472fc05778e261e7b8e (diff) | |
| download | rust-33009601afefcd79cd500b12ccc1b3ab5eda11f1.tar.gz rust-33009601afefcd79cd500b12ccc1b3ab5eda11f1.zip | |
Add documentation on `ast::Attribute`
| -rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 9311af28f54..54e826585d2 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -136,6 +136,13 @@ impl Attribute { } } + /// Returns a list of meta items if the attribute is delimited with parenthesis: + /// + /// ```text + /// #[attr(a, b = "c")] // Returns `Some()`. + /// #[attr = ""] // Returns `None`. + /// #[attr] // Returns `None`. + /// ``` pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> { match &self.kind { AttrKind::Normal(normal) => normal.item.meta_item_list(), @@ -143,6 +150,21 @@ impl Attribute { } } + /// Returns the string value in: + /// + /// ```text + /// #[attribute = "value"] + /// ^^^^^^^ + /// ``` + /// + /// It returns `None` in any other cases, including doc comments if they + /// are not under the form `#[doc = "..."]`. + /// + /// It also returns `None` for: + /// + /// ```text + /// #[attr("value")] + /// ``` pub fn value_str(&self) -> Option<Symbol> { match &self.kind { AttrKind::Normal(normal) => normal.item.value_str(), @@ -232,6 +254,18 @@ impl AttrItem { } } + /// Returns the string value in: + /// + /// ```text + /// #[attribute = "value"] + /// ^^^^^^^ + /// ``` + /// + /// It returns `None` in any other cases like: + /// + /// ```text + /// #[attr("value")] + /// ``` fn value_str(&self) -> Option<Symbol> { match &self.args { AttrArgs::Eq(_, args) => args.value_str(), @@ -315,6 +349,18 @@ impl MetaItem { Some(self.name_value_literal()?.span) } + /// Returns the string value in: + /// + /// ```text + /// #[attribute = "value"] + /// ^^^^^^^ + /// ``` + /// + /// It returns `None` in any other cases like: + /// + /// ```text + /// #[attr("value")] + /// ``` pub fn value_str(&self) -> Option<Symbol> { match &self.kind { MetaItemKind::NameValue(v) => v.kind.str(), |
