diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index 0e3e7909afb84..b93463e99fd5c 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -319,7 +319,7 @@ impl Printer { let mut left_size = self.buf.first().unwrap().size; while left_size >= 0 { - let left = self.buf.first().unwrap().token.clone(); + let left = self.buf.pop_first().unwrap().token; let len = match left { Token::Break(b) => b.blank_space, @@ -335,7 +335,6 @@ impl Printer { self.left_total += len; - self.buf.advance_left(); if self.buf.is_empty() { break; } diff --git a/compiler/rustc_ast_pretty/src/pp/ring.rs b/compiler/rustc_ast_pretty/src/pp/ring.rs index d20142eb591fe..8187394fe30e0 100644 --- a/compiler/rustc_ast_pretty/src/pp/ring.rs +++ b/compiler/rustc_ast_pretty/src/pp/ring.rs @@ -32,11 +32,6 @@ impl RingBuffer { index } - pub fn advance_left(&mut self) { - self.data.pop_front().unwrap(); - self.offset += 1; - } - pub fn clear(&mut self) { self.data.clear(); } @@ -53,6 +48,12 @@ impl RingBuffer { self.data.front_mut() } + pub fn pop_first(&mut self) -> Option { + let first = self.data.pop_front()?; + self.offset += 1; + Some(first) + } + pub fn last(&self) -> Option<&T> { self.data.back() }