allow empty doc comments

This commit is contained in:
Aleksey Kladov 2019-04-02 10:34:34 +03:00
parent ae282d8da6
commit 99e6438660

View file

@ -107,11 +107,13 @@ pub trait DocCommentsOwner: AstNode {
/// Returns the textual content of a doc comment block as a single string. /// Returns the textual content of a doc comment block as a single string.
/// That is, strips leading `///` (+ optional 1 character of whitespace) /// That is, strips leading `///` (+ optional 1 character of whitespace)
/// and joins lines. /// and joins lines.
fn doc_comment_text(&self) -> Option<std::string::String> { fn doc_comment_text(&self) -> Option<String> {
let mut has_comments = false;
let docs = self let docs = self
.doc_comments() .doc_comments()
.filter(|comment| comment.is_doc_comment()) .filter(|comment| comment.is_doc_comment())
.map(|comment| { .map(|comment| {
has_comments = true;
let prefix_len = comment.prefix().len(); let prefix_len = comment.prefix().len();
let line = comment.text().as_str(); let line = comment.text().as_str();
@ -128,10 +130,10 @@ pub trait DocCommentsOwner: AstNode {
}) })
.join("\n"); .join("\n");
if docs.is_empty() { if has_comments {
None
} else {
Some(docs) Some(docs)
} else {
None
} }
} }
} }