summaryrefslogtreecommitdiff
path: root/compiler/rustc_ast_pretty/src/pprust/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state.rs')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index 17941058ed6..044f6b228dc 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -329,9 +329,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
CommentStyle::BlankLine => {
// We need to do at least one, possibly two hardbreaks.
let twice = match self.last_token() {
- pp::Token::String(s) => ";" == s,
- pp::Token::Begin(_) => true,
- pp::Token::End => true,
+ Some(pp::Token::String(s)) => ";" == s,
+ Some(pp::Token::Begin(_)) => true,
+ Some(pp::Token::End) => true,
_ => false,
};
if twice {
@@ -687,11 +687,15 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
if !self.is_beginning_of_line() {
self.break_offset(n, off)
- } else if off != 0 && self.last_token().is_hardbreak_tok() {
- // We do something pretty sketchy here: tuck the nonzero
- // offset-adjustment we were going to deposit along with the
- // break into the previous hardbreak.
- self.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
+ } else if off != 0 {
+ if let Some(last_token) = self.last_token_still_buffered() {
+ if last_token.is_hardbreak_tok() {
+ // We do something pretty sketchy here: tuck the nonzero
+ // offset-adjustment we were going to deposit along with the
+ // break into the previous hardbreak.
+ self.replace_last_token_still_buffered(pp::Printer::hardbreak_tok_offset(off));
+ }
+ }
}
}