From 38167a806cd14dd744d4770c7e13ab2c5e44e69c Mon Sep 17 00:00:00 2001 From: vacuus Date: Sat, 18 Dec 2021 21:54:59 -0500 Subject: [PATCH] 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 --- src/librustdoc/clean/types.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 24e18bb3a51f..0c60952f4500 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -939,7 +939,13 @@ crate enum DocFragmentKind { // `need_backline` field). fn add_doc_fragment(out: &mut String, frag: &DocFragment) { let s = frag.doc.as_str(); - let mut iter = s.lines().peekable(); + let mut iter = s.lines(); + if s == "" { + if frag.need_backline { + out.push('\n'); + } + return; + } while let Some(line) = iter.next() { if line.chars().any(|c| !c.is_whitespace()) { assert!(line.len() >= frag.indent); @@ -947,13 +953,11 @@ fn add_doc_fragment(out: &mut String, frag: &DocFragment) { } else { out.push_str(line); } - if iter.peek().is_some() { - out.push('\n'); - } - } - if frag.need_backline { out.push('\n'); } + if !frag.need_backline { + out.pop(); + } } /// Collapse a collection of [`DocFragment`]s into one string,