Skip to content

Commit 21c1571

Browse files
committed
Deduplicate branches of print_break implementation
1 parent 51eeb82 commit 21c1571

File tree

1 file changed

+14
-19
lines changed
  • compiler/rustc_ast_pretty/src

1 file changed

+14
-19
lines changed

compiler/rustc_ast_pretty/src/pp.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -385,26 +385,21 @@ impl Printer {
385385
}
386386

387387
fn print_break(&mut self, token: BreakToken, size: isize) {
388-
match self.get_top() {
389-
PrintFrame::Fits => {
390-
self.pending_indentation += token.blank_space;
391-
self.space -= token.blank_space;
392-
}
393-
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => {
394-
self.out.push('\n');
395-
self.pending_indentation = offset + token.offset;
396-
self.space = self.margin - (offset + token.offset);
397-
}
398-
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
399-
if size > self.space {
400-
self.out.push('\n');
401-
self.pending_indentation = offset + token.offset;
402-
self.space = self.margin - (offset + token.offset);
403-
} else {
404-
self.pending_indentation += token.blank_space;
405-
self.space -= token.blank_space;
388+
let break_offset =
389+
match self.get_top() {
390+
PrintFrame::Fits => None,
391+
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => Some(offset),
392+
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
393+
if size > self.space { Some(offset) } else { None }
406394
}
407-
}
395+
};
396+
if let Some(offset) = break_offset {
397+
self.out.push('\n');
398+
self.pending_indentation = offset + token.offset;
399+
self.space = self.margin - (offset + token.offset);
400+
} else {
401+
self.pending_indentation += token.blank_space;
402+
self.space -= token.blank_space;
408403
}
409404
}
410405

0 commit comments

Comments
 (0)