Skip to content

Commit 1abbb92

Browse files
committed
Remove token::{Open,Close}Delim.
By replacing them with `{Open,Close}{Param,Brace,Bracket,Invisible}`. PR #137902 made `ast::TokenKind` more like `lexer::TokenKind` by replacing the compound `BinOp{,Eq}(BinOpToken)` variants with fieldless variants `Plus`, `Minus`, `Star`, etc. This commit does a similar thing with delimiters. It also makes `ast::TokenKind` more similar to `parser::TokenType`. This requires a few new methods: - `TokenKind::is_{,open_,close_}delim()` replace various kinds of pattern matches. - `Delimiter::as_{open,close}_token_kind` are used to convert `Delimiter` values to `TokenKind`. Despite these additions, it's a net reduction in lines of code. This is because e.g. `token::OpenParen` is so much shorter than `token::OpenDelim(Delimiter::Parenthesis)` that many multi-line forms reduce to single line forms. And many places where the number of lines doesn't change are still easier to read, just because the names are shorter, e.g.: ``` - } else if self.token != token::CloseDelim(Delimiter::Brace) { + } else if self.token != token::CloseBrace { ```
1 parent e80a221 commit 1abbb92

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/macros.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ fn last_tok(tt: &TokenTree) -> Token {
722722
match *tt {
723723
TokenTree::Token(ref t, _) => t.clone(),
724724
TokenTree::Delimited(delim_span, _, delim, _) => Token {
725-
kind: TokenKind::CloseDelim(delim),
725+
kind: delim.as_open_token_kind(),
726726
span: delim_span.close,
727727
},
728728
}
@@ -1124,8 +1124,14 @@ fn next_space(tok: &TokenKind) -> SpaceState {
11241124
TokenKind::PathSep
11251125
| TokenKind::Pound
11261126
| TokenKind::Dollar
1127-
| TokenKind::OpenDelim(_)
1128-
| TokenKind::CloseDelim(_) => SpaceState::Never,
1127+
| TokenKind::OpenParen
1128+
| TokenKind::CloseParen
1129+
| TokenKind::OpenBrace
1130+
| TokenKind::CloseBrace
1131+
| TokenKind::OpenBracket
1132+
| TokenKind::CloseBracket
1133+
| TokenKind::OpenInvisible(_)
1134+
| TokenKind::CloseInvisible(_) => SpaceState::Never,
11291135

11301136
TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(..) => {
11311137
SpaceState::Ident

src/parse/macros/cfg_if.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::panic::{AssertUnwindSafe, catch_unwind};
22

33
use rustc_ast::ast;
4-
use rustc_ast::token::{Delimiter, TokenKind};
4+
use rustc_ast::token::TokenKind;
55
use rustc_parse::exp;
66
use rustc_parse::parser::ForceCollect;
77
use rustc_span::symbol::kw;
@@ -60,9 +60,7 @@ fn parse_cfg_if_inner<'a>(
6060
return Err("Expected an opening brace");
6161
}
6262

63-
while parser.token != TokenKind::CloseDelim(Delimiter::Brace)
64-
&& parser.token.kind != TokenKind::Eof
65-
{
63+
while parser.token != TokenKind::CloseBrace && parser.token.kind != TokenKind::Eof {
6664
let item = match parser.parse_item(ForceCollect::No) {
6765
Ok(Some(item_ptr)) => item_ptr.into_inner(),
6866
Ok(None) => continue,

0 commit comments

Comments
 (0)