diff options
| author | bors <bors@rust-lang.org> | 2019-08-26 13:45:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-08-26 13:45:18 +0000 |
| commit | 9fa8f140233047fb0211dbaee531a290bcfeae7e (patch) | |
| tree | 332940807d5b52e58a0921474e419fd7efbcd3be /src/libsyntax | |
| parent | 555d7a2fd6165b614cfc01136d8e3f5c465a1582 (diff) | |
| parent | 5b7df0922ef15a8b105aceda8770faedc58ec67b (diff) | |
| download | rust-9fa8f140233047fb0211dbaee531a290bcfeae7e.tar.gz rust-9fa8f140233047fb0211dbaee531a290bcfeae7e.zip | |
Auto merge of #63897 - petrochenkov:prettycomma, r=estebank
pprust: Do not print spaces before some tokens Fixes https://github.com/rust-lang/rust/issues/63896 r? @Mark-Simulacrum
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4dc00af4860..83a926a6217 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 => "+", @@ -696,7 +708,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); |
