summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-01-18 19:20:33 -0800
committerDavid Tolnay <dtolnay@gmail.com>2022-01-18 19:20:33 -0800
commita37d272892172dfe598d9df182fa908d74359c6e (patch)
treefe40e1ced9368e650f5da2cf48ad54d8321a7411
parent0490e43422b3061ba3afef9b064a9360871d1455 (diff)
downloadrust-a37d272892172dfe598d9df182fa908d74359c6e.tar.gz
Implement check_stack nonrecursively
-rw-r--r--compiler/rustc_ast_pretty/src/pp.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs
index d32cc4694d3..dca0515a330 100644
--- a/compiler/rustc_ast_pretty/src/pp.rs
+++ b/compiler/rustc_ast_pretty/src/pp.rs
@@ -378,27 +378,28 @@ impl Printer {
}
}
- fn check_stack(&mut self, k: usize) {
- if let Some(&x) = self.scan_stack.front() {
+ fn check_stack(&mut self, mut k: usize) {
+ while let Some(&x) = self.scan_stack.front() {
match self.buf[x].token {
Token::Begin(_) => {
- if k > 0 {
- self.scan_stack.pop_front().unwrap();
- self.buf[x].size += self.right_total;
- self.check_stack(k - 1);
+ if k == 0 {
+ break;
}
+ self.scan_stack.pop_front().unwrap();
+ self.buf[x].size += self.right_total;
+ k -= 1;
}
Token::End => {
// paper says + not =, but that makes no sense.
self.scan_stack.pop_front().unwrap();
self.buf[x].size = 1;
- self.check_stack(k + 1);
+ k += 1;
}
_ => {
self.scan_stack.pop_front().unwrap();
self.buf[x].size += self.right_total;
- if k > 0 {
- self.check_stack(k);
+ if k == 0 {
+ break;
}
}
}