Skip to content

Commit fcec76b

Browse files
committed
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.
1 parent 4ba5068 commit fcec76b

File tree

1 file changed

+7
-18
lines changed
  • compiler/rustc_ast_pretty/src/pprust

1 file changed

+7
-18
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,13 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
156156
}
157157
}
158158
match tt {
159-
TokenTree::Token(token) => match token.kind {
160-
token::Comma => false,
161-
_ => true,
162-
},
163-
TokenTree::Delimited(_, DelimToken::Paren, _) => match prev {
164-
TokenTree::Token(token) => match token.kind {
165-
token::Ident(_, _) => false,
166-
_ => true,
167-
},
168-
_ => true,
169-
},
170-
TokenTree::Delimited(_, DelimToken::Bracket, _) => match prev {
171-
TokenTree::Token(token) => match token.kind {
172-
token::Pound => false,
173-
_ => true,
174-
},
175-
_ => true,
176-
},
159+
TokenTree::Token(token) => token.kind != token::Comma,
160+
TokenTree::Delimited(_, DelimToken::Paren, _) => {
161+
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }))
162+
}
163+
TokenTree::Delimited(_, DelimToken::Bracket, _) => {
164+
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }))
165+
}
177166
TokenTree::Delimited(..) => true,
178167
}
179168
}

0 commit comments

Comments
 (0)