@@ -150,6 +150,8 @@ pub fn print_crate<'a>(
150
150
/// and also addresses some specific regressions described in #63896 and #73345.
151
151
fn tt_prepend_space ( tt : & TokenTree , prev : & TokenTree ) -> bool {
152
152
if let TokenTree :: Token ( token, _) = prev {
153
+ // No space after these tokens, e.g. `x.y`, `$e`
154
+ // (The carets point to `prev`.) ^ ^
153
155
if matches ! ( token. kind, token:: Dot | token:: Dollar ) {
154
156
return false ;
155
157
}
@@ -158,10 +160,19 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
158
160
}
159
161
}
160
162
match tt {
163
+ // No space before these tokens, e.g. `foo,`, `println!`, `x.y`
164
+ // (The carets point to `token`.) ^ ^ ^
165
+ //
166
+ // FIXME: having `Not` here works well for macro invocations like
167
+ // `println!`, but is bad when `!` means "logical not" or "the never
168
+ // type", where the lack of space causes ugliness like this:
169
+ // `Fn() ->!`, `x =! y`, `if! x { f(); }`.
161
170
TokenTree :: Token ( token, _) => !matches ! ( token. kind, token:: Comma | token:: Not | token:: Dot ) ,
171
+ // No space before parentheses if preceded by these tokens, e.g. `foo(...)`
162
172
TokenTree :: Delimited ( _, Delimiter :: Parenthesis , _) => {
163
173
!matches ! ( prev, TokenTree :: Token ( Token { kind: token:: Ident ( ..) , .. } , _) )
164
174
}
175
+ // No space before brackets if preceded by these tokens, e.g. `#[...]`
165
176
TokenTree :: Delimited ( _, Delimiter :: Bracket , _) => {
166
177
!matches ! ( prev, TokenTree :: Token ( Token { kind: token:: Pound , .. } , _) )
167
178
}
0 commit comments