Skip to content

Commit 5a80e50

Browse files
committed
Add helpful comments to tt_prepend_space.
1 parent 434bfc3 commit 5a80e50

File tree

1 file changed

+6
-0
lines changed
  • compiler/rustc_ast_pretty/src/pprust

1 file changed

+6
-0
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pub fn print_crate<'a>(
150150
/// and also addresses some specific regressions described in #63896 and #73345.
151151
fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
152152
if let TokenTree::Token(token, _) = prev {
153+
// No space after these tokens, e.g. `x.y`, `$e`
154+
// (The carets point to `prev`.) ^ ^
153155
if matches!(token.kind, token::Dot | token::Dollar) {
154156
return false;
155157
}
@@ -158,10 +160,14 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
158160
}
159161
}
160162
match tt {
163+
// No space before these tokens, e.g. `foo,`, `println!`, `x.y`
164+
// (The carets point to `token`.) ^ ^ ^
161165
TokenTree::Token(token, _) => !matches!(token.kind, token::Comma | token::Not | token::Dot),
166+
// No space before parentheses if preceded by these tokens, e.g. `foo(...)`
162167
TokenTree::Delimited(_, Delimiter::Parenthesis, _) => {
163168
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }, _))
164169
}
170+
// No space before brackets if preceded by these tokens, e.g. `#[...]`
165171
TokenTree::Delimited(_, Delimiter::Bracket, _) => {
166172
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }, _))
167173
}

0 commit comments

Comments
 (0)