Skip to content

Commit

Permalink
Deduplicate branches of print_break implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 20, 2022
1 parent 51eeb82 commit 21c1571
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,21 @@ impl Printer {
}

fn print_break(&mut self, token: BreakToken, size: isize) {
match self.get_top() {
PrintFrame::Fits => {
self.pending_indentation += token.blank_space;
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 } => {
if size > self.space {
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
} else {
self.pending_indentation += token.blank_space;
self.space -= token.blank_space;
let break_offset =
match self.get_top() {
PrintFrame::Fits => None,
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => Some(offset),
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
if size > self.space { Some(offset) } else { None }
}
}
};
if let Some(offset) = break_offset {
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
} else {
self.pending_indentation += token.blank_space;
self.space -= token.blank_space;
}
}

Expand Down

0 comments on commit 21c1571

Please sign in to comment.