Skip to content

Commit 38167a8

Browse files
committed
Omit check of a successive line in loop
I think that s == "" is the only edge case (as it makes iter.next() return None the first time). The early return is necessary so that the last character of 'out' isn't popped if s == "" && !frag.need_backline
1 parent 41c3017 commit 38167a8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: src/librustdoc/clean/types.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -939,21 +939,25 @@ crate enum DocFragmentKind {
939939
// `need_backline` field).
940940
fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
941941
let s = frag.doc.as_str();
942-
let mut iter = s.lines().peekable();
942+
let mut iter = s.lines();
943+
if s == "" {
944+
if frag.need_backline {
945+
out.push('\n');
946+
}
947+
return;
948+
}
943949
while let Some(line) = iter.next() {
944950
if line.chars().any(|c| !c.is_whitespace()) {
945951
assert!(line.len() >= frag.indent);
946952
out.push_str(&line[frag.indent..]);
947953
} else {
948954
out.push_str(line);
949955
}
950-
if iter.peek().is_some() {
951-
out.push('\n');
952-
}
953-
}
954-
if frag.need_backline {
955956
out.push('\n');
956957
}
958+
if !frag.need_backline {
959+
out.pop();
960+
}
957961
}
958962

959963
/// Collapse a collection of [`DocFragment`]s into one string,

0 commit comments

Comments
 (0)