Skip to content

Commit 9a3c907

Browse files
committed
Make some matches exhaustive in nonterminal.rs.
For ones matching more than one or two variants, this is easier to think about.
1 parent f8a21a5 commit 9a3c907

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ impl<'a> Parser<'a> {
2020
pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool {
2121
/// Checks whether the non-terminal may contain a single (non-keyword) identifier.
2222
fn may_be_ident(nt: &token::Nonterminal) -> bool {
23-
!matches!(*nt, NtItem(_) | NtBlock(_) | NtVis(_) | NtLifetime(_))
23+
match nt {
24+
NtStmt(_)
25+
| NtPat(_)
26+
| NtExpr(_)
27+
| NtTy(_)
28+
| NtIdent(..)
29+
| NtLiteral(_) // `true`, `false`
30+
| NtMeta(_)
31+
| NtPath(_) => true,
32+
33+
NtItem(_)
34+
| NtBlock(_)
35+
| NtVis(_)
36+
| NtLifetime(_) => false,
37+
}
2438
}
2539

2640
match kind {
@@ -41,10 +55,11 @@ impl<'a> Parser<'a> {
4155
},
4256
NonterminalKind::Block => match &token.kind {
4357
token::OpenDelim(Delimiter::Brace) => true,
44-
token::Interpolated(nt) => !matches!(
45-
**nt,
46-
NtItem(_) | NtPat(_) | NtTy(_) | NtIdent(..) | NtMeta(_) | NtPath(_) | NtVis(_)
47-
),
58+
token::Interpolated(nt) => match **nt {
59+
NtBlock(_) | NtLifetime(_) | NtStmt(_) | NtExpr(_) | NtLiteral(_) => true,
60+
NtItem(_) | NtPat(_) | NtTy(_) | NtIdent(..) | NtMeta(_) | NtPath(_)
61+
| NtVis(_) => false,
62+
},
4863
_ => false,
4964
},
5065
NonterminalKind::Path | NonterminalKind::Meta => match &token.kind {

0 commit comments

Comments
 (0)