pprust: Do not print spaces before some tokens
This commit is contained in:
parent
d760df5aea
commit
5b7df0922e
9 changed files with 24 additions and 15 deletions
|
@ -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);
|
||||
|
|
|
@ -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() { }
|
||||
}
|
||||
|
|
|
@ -99,8 +99,5 @@ fn main() {
|
|||
'\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); }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,5 +2,5 @@
|
|||
|
||||
fn main() {
|
||||
let x = match { 5 } { 1 => 5, 2 => 6, _ => 7, };
|
||||
assert_eq!(x , 7);
|
||||
assert_eq!(x, 7);
|
||||
}
|
||||
|
|
|
@ -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 ;));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue