about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-25 20:41:52 +0300
committerJosh Stone <jistone@redhat.com>2019-09-13 10:28:46 -0700
commit31b4b771c9efa37e7f76545a68ed0afc3cdf4cee (patch)
treea1aa54c414ad12bff772a4d3f83f503fdf66b2f9 /src/libsyntax
parent46049e70f6fee53a316ae707402490feaf296a6c (diff)
pprust: Do not print spaces before some tokens
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/print/pprust.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index bda761244d5..536687bdbed 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -152,6 +152,18 @@ pub fn to_string<F>(f: F) -> String where
     printer.s.eof()
 }
 
+// This makes comma-separated lists look slightly nicer,
+// and also addresses a specific regression described in issue #63896.
+fn tt_prepend_space(tt: &TokenTree) -> bool {
+    match tt {
+        TokenTree::Token(token) => match token.kind {
+            token::Comma => false,
+            _ => true,
+        }
+        _ => true,
+    }
+}
+
 fn binop_to_string(op: BinOpToken) -> &'static str {
     match op {
         token::Plus     => "+",
@@ -684,7 +696,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
 
     fn print_tts(&mut self, tts: tokenstream::TokenStream, convert_dollar_crate: bool) {
         for (i, tt) in tts.into_trees().enumerate() {
-            if i != 0 {
+            if i != 0 && tt_prepend_space(&tt) {
                 self.space();
             }
             self.print_tt(tt, convert_dollar_crate);