mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
pprust: Do not print spaces before some tokens
This commit is contained in:
parent
d760df5aea
commit
5b7df0922e
@ -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);
|
||||
|
@ -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); }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user