Skip to content

Commit

Permalink
Auto merge of #63897 - petrochenkov:prettycomma, r=estebank
Browse files Browse the repository at this point in the history
pprust: Do not print spaces before some tokens

Fixes #63896

r? @Mark-Simulacrum
  • Loading branch information
bors committed Aug 26, 2019
2 parents 555d7a2 + 5b7df09 commit 9fa8f14
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
14 changes: 13 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "+",
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/pretty/attr-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#![feature(rustc_attrs)]

fn main() {
#![rustc_dummy("hi" , 1 , 2 , 1.012 , pi = 3.14 , bye , name ("John"))]
#![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name ("John"))]
#[rustc_dummy = 8]
fn f() { }

#[rustc_dummy(1 , 2 , 3)]
#[rustc_dummy(1, 2, 3)]
fn g() { }
}
5 changes: 1 addition & 4 deletions src/test/pretty/block-comment-wchar.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,5 @@
'\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}',
'\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}',
'\u{205F}', '\u{3000}'];
for c in &chars {
let ws = c.is_whitespace();
println!("{} {}" , c , ws);
}
for c in &chars { let ws = c.is_whitespace(); println!("{} {}", c, ws); }
}
2 changes: 1 addition & 1 deletion src/test/pretty/delimited-token-groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
macro_rules! mac { ($ ($ tt : tt) *) => () }

mac! {
struct S { field1 : u8 , field2 : u16 , } impl Clone for S
struct S { field1 : u8, field2 : u16, } impl Clone for S
{
fn clone () -> S
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/do1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

fn f<F>(f: F) where F: Fn(isize) { f(10) }

fn main() { f(|i| { assert_eq!(i , 10) }) }
fn main() { f(|i| { assert_eq!(i, 10) }) }
2 changes: 1 addition & 1 deletion src/test/pretty/match-block-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

fn main() {
let x = match { 5 } { 1 => 5, 2 => 6, _ => 7, };
assert_eq!(x , 7);
assert_eq!(x, 7);
}
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-first-set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ macro_rules! foo_26444 {
}

fn test_26444() {
assert_eq!("a , b , c , d , e", foo_26444!(a, b; c; d, e));
assert_eq!("a, b, c, d, e", foo_26444!(a, b; c; d, e));
assert_eq!("f", foo_26444!(; f ;));
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/proc-macro/auxiliary/attr-stmt-expr-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println!(\"{}\" , string);");
assert_eq!(item.to_string(), "println!(\"{}\", string);");
item
}

Expand All @@ -31,7 +31,7 @@ pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println!(\"{}\" , string)");
assert_eq!(item.to_string(), "println!(\"{}\", string)");
item
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/proc-macro/auxiliary/attr-stmt-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println!(\"{}\" , string);");
assert_eq!(item.to_string(), "println!(\"{}\", string);");
item
}

Expand All @@ -31,7 +31,7 @@ pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println!(\"{}\" , string)");
assert_eq!(item.to_string(), "println!(\"{}\", string)");
item
}

Expand Down

0 comments on commit 9fa8f14

Please sign in to comment.