1
Fork 0

Deduplicate branches of print_break implementation

This commit is contained in:
David Tolnay 2022-01-19 18:58:33 -08:00
parent 51eeb82d9d
commit 21c1571e79
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -385,18 +385,15 @@ impl Printer {
} }
fn print_break(&mut self, token: BreakToken, size: isize) { fn print_break(&mut self, token: BreakToken, size: isize) {
let break_offset =
match self.get_top() { match self.get_top() {
PrintFrame::Fits => { PrintFrame::Fits => None,
self.pending_indentation += token.blank_space; PrintFrame::Broken { offset, breaks: Breaks::Consistent } => Some(offset),
self.space -= token.blank_space;
}
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => {
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
}
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => { PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
if size > self.space { if size > self.space { Some(offset) } else { None }
}
};
if let Some(offset) = break_offset {
self.out.push('\n'); self.out.push('\n');
self.pending_indentation = offset + token.offset; self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset); self.space = self.margin - (offset + token.offset);
@ -405,8 +402,6 @@ impl Printer {
self.space -= token.blank_space; self.space -= token.blank_space;
} }
} }
}
}
fn print_string(&mut self, string: &str) { fn print_string(&mut self, string: &str) {
// Write the pending indent. A more concise way of doing this would be: // Write the pending indent. A more concise way of doing this would be: