about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-01-19 18:46:49 -0800
committerDavid Tolnay <dtolnay@gmail.com>2022-01-19 19:04:33 -0800
commit65dd67096e6771a3bdf5b9b4a4cd638777a0ae89 (patch)
treeb7324d91b135c8d9db7035a76a0e82a1f2c3a5d1
parentd5f15a8c18a80cce04641e4801deee94b3a0bf45 (diff)
downloadrust-65dd67096e6771a3bdf5b9b4a4cd638777a0ae89.tar.gz
rust-65dd67096e6771a3bdf5b9b4a4cd638777a0ae89.zip
Touch up print_string
-rw-r--r--compiler/rustc_ast_pretty/src/pp.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs
index dadfac06847..11114b53220 100644
--- a/compiler/rustc_ast_pretty/src/pp.rs
+++ b/compiler/rustc_ast_pretty/src/pp.rs
@@ -137,6 +137,7 @@ mod ring;
 use ring::RingBuffer;
 use std::borrow::Cow;
 use std::collections::VecDeque;
+use std::iter;
 
 /// How to break. Described in more detail in the module docs.
 #[derive(Clone, Copy, PartialEq)]
@@ -425,10 +426,6 @@ impl Printer {
     }
 
     fn print_string(&mut self, string: &str) {
-        let len = string.len() as isize;
-        // assert!(len <= space);
-        self.space -= len;
-
         // Write the pending indent. A more concise way of doing this would be:
         //
         //   write!(self.out, "{: >n$}", "", n = self.pending_indentation as usize)?;
@@ -436,9 +433,11 @@ impl Printer {
         // But that is significantly slower. This code is sufficiently hot, and indents can get
         // sufficiently large, that the difference is significant on some workloads.
         self.out.reserve(self.pending_indentation as usize);
-        self.out.extend(std::iter::repeat(' ').take(self.pending_indentation as usize));
+        self.out.extend(iter::repeat(' ').take(self.pending_indentation as usize));
         self.pending_indentation = 0;
+
         self.out.push_str(string);
+        self.space -= string.len() as isize;
     }
 
     // Convenience functions to talk to the printer.