Skip to content

Commit

Permalink
Rollup merge of #77888 - LingMan:ast_pretty_tt_prepend_space, r=jyn514
Browse files Browse the repository at this point in the history
Simplify a nested bool match

Logically this first eliminates the innermost match by merging the patterns.
Then, in a second step, turns the newly innermost match into a `matches!` call.
  • Loading branch information
JohnTitor authored Oct 30, 2020
2 parents 0723b27 + fcec76b commit 439ea4b
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,13 @@ 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,
},
TokenTree::Delimited(_, DelimToken::Bracket, _) => match prev {
TokenTree::Token(token) => match token.kind {
token::Pound => false,
_ => true,
},
_ => true,
},
TokenTree::Token(token) => token.kind != token::Comma,
TokenTree::Delimited(_, DelimToken::Paren, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }))
}
TokenTree::Delimited(_, DelimToken::Bracket, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }))
}
TokenTree::Delimited(..) => true,
}
}
Expand Down

0 comments on commit 439ea4b

Please sign in to comment.