Skip to content

Commit a35c855

Browse files
committed
Address review comments.
1 parent 44c9e77 commit a35c855

File tree

15 files changed

+31
-32
lines changed

15 files changed

+31
-32
lines changed

compiler/rustc_ast/src/token.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ impl TokenKind {
573573
}
574574

575575
pub fn is_delim(&self) -> bool {
576-
self.is_open_delim().is_some() | self.is_close_delim().is_some()
576+
self.open_delim().is_some() || self.close_delim().is_some()
577577
}
578578

579-
pub fn is_open_delim(&self) -> Option<Delimiter> {
579+
pub fn open_delim(&self) -> Option<Delimiter> {
580580
match *self {
581581
OpenParen => Some(Delimiter::Parenthesis),
582582
OpenBrace => Some(Delimiter::Brace),
@@ -586,7 +586,7 @@ impl TokenKind {
586586
}
587587
}
588588

589-
pub fn is_close_delim(&self) -> Option<Delimiter> {
589+
pub fn close_delim(&self) -> Option<Delimiter> {
590590
match *self {
591591
CloseParen => Some(Delimiter::Parenthesis),
592592
CloseBrace => Some(Delimiter::Brace),

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
13001300
use mbe::TokenTree;
13011301

13021302
if let TokenTree::Token(Token { kind, .. }) = tok
1303-
&& kind.is_close_delim().is_some()
1303+
&& kind.close_delim().is_some()
13041304
{
13051305
// closing a token tree can never be matched by any fragment;
13061306
// iow, we always require that `(` and `)` match, etc.

compiler/rustc_expand/src/proc_macro_server.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
309309
}
310310

311311
OpenParen | CloseParen | OpenBrace | CloseBrace | OpenBracket | CloseBracket
312-
| OpenInvisible(_) | CloseInvisible(_) => unreachable!(),
313-
Eof => unreachable!(),
312+
| OpenInvisible(_) | CloseInvisible(_) | Eof => unreachable!(),
314313
}
315314
}
316315
trees

compiler/rustc_parse/src/lexer/tokentrees.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
1818

1919
let mut buf = Vec::new();
2020
loop {
21-
if let Some(delim) = self.token.kind.is_open_delim() {
21+
if let Some(delim) = self.token.kind.open_delim() {
2222
// Invisible delimiters cannot occur here because `TokenTreesReader` parses
2323
// code directly from strings, with no macro expansion involved.
2424
debug_assert!(!matches!(delim, Delimiter::Invisible(_)));
2525
buf.push(match self.lex_token_tree_open_delim(delim) {
2626
Ok(val) => val,
2727
Err(errs) => return Err(errs),
2828
})
29-
} else if let Some(delim) = self.token.kind.is_close_delim() {
29+
} else if let Some(delim) = self.token.kind.close_delim() {
3030
// Invisible delimiters cannot occur here because `TokenTreesReader` parses
3131
// code directly from strings, with no macro expansion involved.
3232
debug_assert!(!matches!(delim, Delimiter::Invisible(_)));
@@ -35,7 +35,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
3535
} else {
3636
Err(vec![self.close_delim_err(delim)])
3737
};
38-
} else if let token::Eof = self.token.kind {
38+
} else if self.token.kind == token::Eof {
3939
return if is_delimited {
4040
Err(vec![self.eof_err()])
4141
} else {
@@ -106,7 +106,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
106106
let delim_span = DelimSpan::from_pair(pre_span, self.token.span);
107107
let sm = self.psess.source_map();
108108

109-
let close_spacing = if let Some(close_delim) = self.token.kind.is_close_delim() {
109+
let close_spacing = if let Some(close_delim) = self.token.kind.close_delim() {
110110
if close_delim == open_delim {
111111
// Correct delimiter.
112112
let (open_brace, open_brace_span) = self.diag_info.open_braces.pop().unwrap();

compiler/rustc_parse/src/parser/attr_wrapper.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,12 @@ fn make_attr_token_stream(
502502
for flat_token in iter {
503503
match flat_token {
504504
FlatToken::Token((token @ Token { kind, span }, spacing)) => {
505-
if let Some(delim) = kind.is_open_delim() {
505+
if let Some(delim) = kind.open_delim() {
506506
stack_rest.push(mem::replace(
507507
&mut stack_top,
508508
FrameData { open_delim_sp: Some((delim, span, spacing)), inner: vec![] },
509509
));
510-
} else if let Some(delim) = kind.is_close_delim() {
510+
} else if let Some(delim) = kind.close_delim() {
511511
let frame_data = mem::replace(&mut stack_top, stack_rest.pop().unwrap());
512512
let (open_delim, open_sp, open_spacing) = frame_data.open_delim_sp.unwrap();
513513
assert!(

compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ impl<'a> Parser<'a> {
10331033
) -> PResult<'a, P<Expr>> {
10341034
err.span_label(lo.to(decl_hi), "while parsing the body of this closure");
10351035
let guar = match before.kind {
1036-
token::OpenBrace if !matches!(token.kind, token::OpenBrace) => {
1036+
token::OpenBrace if token.kind != token::OpenBrace => {
10371037
// `{ || () }` should have been `|| { () }`
10381038
err.multipart_suggestion(
10391039
"you might have meant to open the body of the closure, instead of enclosing \
@@ -1048,7 +1048,7 @@ impl<'a> Parser<'a> {
10481048
self.eat_to_tokens(&[exp!(CloseBrace)]);
10491049
guar
10501050
}
1051-
token::OpenParen if !matches!(token.kind, token::OpenBrace) => {
1051+
token::OpenParen if token.kind != token::OpenBrace => {
10521052
// We are within a function call or tuple, we can emit the error
10531053
// and recover.
10541054
self.eat_to_tokens(&[exp!(CloseParen), exp!(Comma)]);
@@ -1063,7 +1063,7 @@ impl<'a> Parser<'a> {
10631063
);
10641064
err.emit()
10651065
}
1066-
_ if !matches!(token.kind, token::OpenBrace) => {
1066+
_ if token.kind != token::OpenBrace => {
10671067
// We don't have a heuristic to correctly identify where the block
10681068
// should be closed.
10691069
err.multipart_suggestion_verbose(
@@ -1462,7 +1462,7 @@ impl<'a> Parser<'a> {
14621462
let modifiers = [(token::Lt, 1), (token::Gt, -1), (token::Shr, -2)];
14631463
self.consume_tts(1, &modifiers);
14641464

1465-
if !&[token::OpenParen, token::PathSep].contains(&self.token.kind) {
1465+
if !matches!(self.token.kind, token::OpenParen | token::PathSep) {
14661466
// We don't have `foo< bar >(` or `foo< bar >::`, so we rewind the
14671467
// parser and bail out.
14681468
self.restore_snapshot(snapshot);

compiler/rustc_parse/src/parser/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ impl<'a> Parser<'a> {
12021202
}
12031203
}
12041204

1205-
if self.token.kind.is_close_delim().is_some() || self.token.kind == token::Comma {
1205+
if self.token.kind.close_delim().is_some() || self.token.kind == token::Comma {
12061206
break;
12071207
} else if trailing_dot.is_none() {
12081208
// This loop should only repeat if there is a trailing dot.
@@ -1680,7 +1680,7 @@ impl<'a> Parser<'a> {
16801680
self.parse_expr_block(label, lo, BlockCheckMode::Default)
16811681
} else if !ate_colon
16821682
&& self.may_recover()
1683-
&& (self.token.kind.is_close_delim().is_some() || self.token.is_punct())
1683+
&& (self.token.kind.close_delim().is_some() || self.token.is_punct())
16841684
&& could_be_unclosed_char_literal(label_.ident)
16851685
{
16861686
let (lit, _) =
@@ -2268,7 +2268,7 @@ impl<'a> Parser<'a> {
22682268
}
22692269

22702270
fn is_array_like_block(&mut self) -> bool {
2271-
matches!(self.token.kind, TokenKind::OpenBrace)
2271+
self.token.kind == TokenKind::OpenBrace
22722272
&& self
22732273
.look_ahead(1, |t| matches!(t.kind, TokenKind::Ident(..) | TokenKind::Literal(_)))
22742274
&& self.look_ahead(2, |t| t == &token::Comma)
@@ -2477,7 +2477,7 @@ impl<'a> Parser<'a> {
24772477
fn parse_closure_block_body(&mut self, ret_span: Span) -> PResult<'a, P<Expr>> {
24782478
if self.may_recover()
24792479
&& self.token.can_begin_expr()
2480-
&& !matches!(self.token.kind, TokenKind::OpenBrace)
2480+
&& self.token.kind != TokenKind::OpenBrace
24812481
&& !self.token.is_metavar_block()
24822482
{
24832483
let snapshot = self.create_snapshot_for_diagnostic();
@@ -2958,7 +2958,7 @@ impl<'a> Parser<'a> {
29582958
let (pat, expr) = self.parse_for_head()?;
29592959
// Recover from missing expression in `for` loop
29602960
if matches!(expr.kind, ExprKind::Block(..))
2961-
&& !matches!(self.token.kind, token::OpenBrace)
2961+
&& self.token.kind != token::OpenBrace
29622962
&& self.may_recover()
29632963
{
29642964
let guar = self

compiler/rustc_parse/src/parser/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a> Parser<'a> {
547547
matches!(t.kind, token::Gt | token::Comma | token::Colon | token::Eq)
548548
// Recovery-only branch -- this could be removed,
549549
// since it only affects diagnostics currently.
550-
|| matches!(t.kind, token::Question)
550+
|| t.kind == token::Question
551551
})
552552
|| self.is_keyword_ahead(start + 1, &[kw::Const]))
553553
}

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl<'a> Parser<'a> {
401401
let ident = if self.token.is_ident()
402402
&& (!is_const || self.look_ahead(1, |t| *t == token::OpenParen))
403403
&& self.look_ahead(1, |t| {
404-
[token::Lt, token::OpenBrace, token::OpenParen].contains(&t.kind)
404+
matches!(t.kind, token::Lt | token::OpenBrace | token::OpenParen)
405405
}) {
406406
self.parse_ident().unwrap()
407407
} else {

compiler/rustc_parse/src/parser/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ impl<'a> Parser<'a> {
14761476

14771477
/// Parses a single token tree from the input.
14781478
pub fn parse_token_tree(&mut self) -> TokenTree {
1479-
if self.token.kind.is_open_delim().is_some() {
1479+
if self.token.kind.open_delim().is_some() {
14801480
// Clone the `TokenTree::Delimited` that we are currently
14811481
// within. That's what we are going to return.
14821482
let tree = self.token_cursor.stack.last().unwrap().curr().unwrap().clone();
@@ -1493,7 +1493,7 @@ impl<'a> Parser<'a> {
14931493
// can capture these tokens if necessary.
14941494
self.bump();
14951495
if self.token_cursor.stack.len() == target_depth {
1496-
debug_assert!(self.token.kind.is_close_delim().is_some());
1496+
debug_assert!(self.token.kind.close_delim().is_some());
14971497
break;
14981498
}
14991499
}

compiler/rustc_parse/src/parser/nonterminal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'a> Parser<'a> {
103103
_ => false,
104104
},
105105
NonterminalKind::TT | NonterminalKind::Item | NonterminalKind::Stmt => {
106-
token.kind.is_close_delim().is_none()
106+
token.kind.close_delim().is_none()
107107
}
108108
}
109109
}

compiler/rustc_parse/src/parser/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a> Parser<'a> {
323323
fn eat_or_separator(&mut self, lo: Option<Span>) -> EatOrResult {
324324
if self.recover_trailing_vert(lo) {
325325
EatOrResult::TrailingVert
326-
} else if matches!(self.token.kind, token::OrOr) {
326+
} else if self.token.kind == token::OrOr {
327327
// Found `||`; Recover and pretend we parsed `|`.
328328
self.dcx().emit_err(UnexpectedVertVertInPattern { span: self.token.span, start: lo });
329329
self.bump();
@@ -364,7 +364,7 @@ impl<'a> Parser<'a> {
364364
span: self.token.span,
365365
start: lo,
366366
token: self.token,
367-
note_double_vert: matches!(self.token.kind, token::OrOr),
367+
note_double_vert: self.token.kind == token::OrOr,
368368
});
369369
self.bump();
370370
true
@@ -835,7 +835,7 @@ impl<'a> Parser<'a> {
835835
// because we never have `'a: label {}` in a pattern position anyways, but it does
836836
// keep us from suggesting something like `let 'a: Ty = ..` => `let 'a': Ty = ..`
837837
&& could_be_unclosed_char_literal(lt)
838-
&& !self.look_ahead(1, |token| matches!(token.kind, token::Colon))
838+
&& !self.look_ahead(1, |token| token.kind == token::Colon)
839839
{
840840
// Recover a `'a` as a `'a'` literal
841841
let lt = self.expect_lifetime();

compiler/rustc_parse/src/parser/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ impl<'a> Parser<'a> {
849849
/// the caller.
850850
pub(super) fn parse_const_arg(&mut self) -> PResult<'a, AnonConst> {
851851
// Parse const argument.
852-
let value = if let token::OpenBrace = self.token.kind {
852+
let value = if self.token.kind == token::OpenBrace {
853853
self.parse_expr_block(None, self.token.span, BlockCheckMode::Default)?
854854
} else {
855855
self.handle_unambiguous_unbraced_const_arg()?

compiler/rustc_parse/src/parser/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl<'a> Parser<'a> {
864864
StmtKind::Expr(expr)
865865
if classify::expr_requires_semi_to_be_stmt(expr)
866866
&& !expr.attrs.is_empty()
867-
&& ![token::Eof, token::Semi, token::CloseBrace].contains(&self.token.kind) =>
867+
&& !matches!(self.token.kind, token::Eof | token::Semi | token::CloseBrace) =>
868868
{
869869
// The user has written `#[attr] expr` which is unsupported. (#106020)
870870
let guar = self.attr_on_non_tail_expr(&expr);

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'a> Parser<'a> {
355355
}
356356
}
357357
} else if self.check_keyword(exp!(Unsafe))
358-
&& self.look_ahead(1, |tok| matches!(tok.kind, token::Lt))
358+
&& self.look_ahead(1, |tok| tok.kind == token::Lt)
359359
{
360360
self.parse_unsafe_binder_ty()?
361361
} else {

0 commit comments

Comments
 (0)