Skip to content

Commit

Permalink
Don't prepend with space before paren
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 17, 2020
1 parent 59f4ba9 commit aa20d96
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,19 @@ pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {

// 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 {
fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
match tt {
TokenTree::Token(token) => match token.kind {
token::Comma => false,
_ => true,
},
TokenTree::Delimited(_, DelimToken::Paren, _) => match prev {
TokenTree::Token(token) => match token.kind {
token::Ident(_, _) => false,
_ => true,
},
_ => true,
},
_ => true,
}
}
Expand Down Expand Up @@ -650,11 +657,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}

fn print_tts(&mut self, tts: tokenstream::TokenStream, convert_dollar_crate: bool) {
for (i, tt) in tts.into_trees().enumerate() {
if i != 0 && tt_prepend_space(&tt) {
let mut iter = tts.into_trees().peekable();
while let Some(tt) = iter.next() {
let show_space =
if let Some(next) = iter.peek() { tt_prepend_space(next, &tt) } else { false };
self.print_tt(tt, convert_dollar_crate);
if show_space {
self.space();
}
self.print_tt(tt, convert_dollar_crate);
}
}

Expand Down

0 comments on commit aa20d96

Please sign in to comment.