Skip to content

Commit 8fa8021

Browse files
authored
Rollup merge of rust-lang#101752 - GuillaumeGomez:improve-attr-docs, r=lqd
Improve Attribute doc methods r? `@lqd`
2 parents f80b38b + c4559eb commit 8fa8021

File tree

1 file changed

+11
-1
lines changed
  • compiler/rustc_ast/src/attr

1 file changed

+11
-1
lines changed

compiler/rustc_ast/src/attr/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,20 @@ impl AttrItem {
232232

233233
impl Attribute {
234234
/// Returns `true` if it is a sugared doc comment (`///` or `//!` for example).
235-
/// So `#[doc = "doc"]` will return `false`.
235+
/// So `#[doc = "doc"]` (which is a doc comment) and `#[doc(...)]` (which is not
236+
/// a doc comment) will return `false`.
236237
pub fn is_doc_comment(&self) -> bool {
237238
match self.kind {
238239
AttrKind::Normal(..) => false,
239240
AttrKind::DocComment(..) => true,
240241
}
241242
}
242243

244+
/// Returns the documentation and its kind if this is a doc comment or a sugared doc comment.
245+
/// * `///doc` returns `Some(("doc", CommentKind::Line))`.
246+
/// * `/** doc */` returns `Some(("doc", CommentKind::Block))`.
247+
/// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`.
248+
/// * `#[doc(...)]` returns `None`.
243249
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
244250
match self.kind {
245251
AttrKind::DocComment(kind, data) => Some((data, kind)),
@@ -252,6 +258,10 @@ impl Attribute {
252258
}
253259
}
254260

261+
/// Returns the documentation if this is a doc comment or a sugared doc comment.
262+
/// * `///doc` returns `Some("doc")`.
263+
/// * `#[doc = "doc"]` returns `Some("doc")`.
264+
/// * `#[doc(...)]` returns `None`.
255265
pub fn doc_str(&self) -> Option<Symbol> {
256266
match self.kind {
257267
AttrKind::DocComment(.., data) => Some(data),

0 commit comments

Comments
 (0)