summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast/src/util/comments.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast/src/util/comments.rs')
-rw-r--r--compiler/rustc_ast/src/util/comments.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/compiler/rustc_ast/src/util/comments.rs b/compiler/rustc_ast/src/util/comments.rs
index 275ed02c2..eece99a3e 100644
--- a/compiler/rustc_ast/src/util/comments.rs
+++ b/compiler/rustc_ast/src/util/comments.rs
@@ -58,23 +58,24 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
// In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
// present. However, we first need to strip the empty lines so they don't get in the middle
// when we try to compute the "horizontal trim".
- let lines = if kind == CommentKind::Block {
- // Whatever happens, we skip the first line.
- let mut i = lines
- .get(0)
- .map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
- .unwrap_or(0);
- let mut j = lines.len();
-
- while i < j && lines[i].trim().is_empty() {
- i += 1;
- }
- while j > i && lines[j - 1].trim().is_empty() {
- j -= 1;
+ let lines = match kind {
+ CommentKind::Block => {
+ // Whatever happens, we skip the first line.
+ let mut i = lines
+ .get(0)
+ .map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
+ .unwrap_or(0);
+ let mut j = lines.len();
+
+ while i < j && lines[i].trim().is_empty() {
+ i += 1;
+ }
+ while j > i && lines[j - 1].trim().is_empty() {
+ j -= 1;
+ }
+ &lines[i..j]
}
- &lines[i..j]
- } else {
- lines
+ CommentKind::Line => lines,
};
for line in lines {