Add helpful comments to tt_prepend_space
.
This commit is contained in:
parent
434bfc3162
commit
3bb85b73b5
@ -150,6 +150,8 @@ pub fn print_crate<'a>(
|
|||||||
/// and also addresses some specific regressions described in #63896 and #73345.
|
/// and also addresses some specific regressions described in #63896 and #73345.
|
||||||
fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
|
fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
|
||||||
if let TokenTree::Token(token, _) = prev {
|
if let TokenTree::Token(token, _) = prev {
|
||||||
|
// No space after these tokens, e.g. `x.y`, `$e`
|
||||||
|
// (The carets point to `prev`.) ^ ^
|
||||||
if matches!(token.kind, token::Dot | token::Dollar) {
|
if matches!(token.kind, token::Dot | token::Dollar) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -158,10 +160,19 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
match tt {
|
match tt {
|
||||||
|
// No space before these tokens, e.g. `foo,`, `println!`, `x.y`
|
||||||
|
// (The carets point to `token`.) ^ ^ ^
|
||||||
|
//
|
||||||
|
// FIXME: having `Not` here works well for macro invocations like
|
||||||
|
// `println!()`, but is bad when `!` means "logical not" or "the never
|
||||||
|
// type", where the lack of space causes ugliness like this:
|
||||||
|
// `Fn() ->!`, `x =! y`, `if! x { f(); }`.
|
||||||
TokenTree::Token(token, _) => !matches!(token.kind, token::Comma | token::Not | token::Dot),
|
TokenTree::Token(token, _) => !matches!(token.kind, token::Comma | token::Not | token::Dot),
|
||||||
|
// No space before parentheses if preceded by these tokens, e.g. `foo(...)`
|
||||||
TokenTree::Delimited(_, Delimiter::Parenthesis, _) => {
|
TokenTree::Delimited(_, Delimiter::Parenthesis, _) => {
|
||||||
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }, _))
|
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }, _))
|
||||||
}
|
}
|
||||||
|
// No space before brackets if preceded by these tokens, e.g. `#[...]`
|
||||||
TokenTree::Delimited(_, Delimiter::Bracket, _) => {
|
TokenTree::Delimited(_, Delimiter::Bracket, _) => {
|
||||||
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }, _))
|
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }, _))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user