1
Fork 0

Don't insert spaces before most semicolons in print_tts.

This gives better output for code produced by proc macros.
This commit is contained in:
Nicholas Nethercote 2023-11-10 14:34:56 +11:00
parent ef71f1047e
commit 41e4a3e086
26 changed files with 59 additions and 73 deletions

View file

@ -160,6 +160,10 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
use TokenTree::Delimited as Del;
use TokenTree::Token as Tok;
fn is_punct(tt: &TokenTree) -> bool {
matches!(tt, TokenTree::Token(tok, _) if tok.is_punct())
}
// Each match arm has one or more examples in comments. The default is to
// insert space between adjacent tokens, except for the cases listed in
// this match.
@ -180,6 +184,9 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
// - Never type: `Fn() ->!`
(_, Tok(Token { kind: Comma | Dot | Not, .. }, _)) => false,
// NON-PUNCT + `;`: `x = 3;`, `[T; 3]`
(tt1, Tok(Token { kind: Semi, .. }, _)) if !is_punct(tt1) => false,
// IDENT + `(`: `f(3)`
//
// FIXME: Incorrect cases: