about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-08-11 09:25:16 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2023-08-17 09:05:37 +1000
commit9a3c907bdbab9c9e444db4c32997bf621936b891 (patch)
treec5606fe6dc5ba1552b1da78c2ce30e13a4ab8c63
parentf8a21a5df03f393f2c666c3033632b0024fa86ee (diff)
downloadrust-9a3c907bdbab9c9e444db4c32997bf621936b891.tar.gz
rust-9a3c907bdbab9c9e444db4c32997bf621936b891.zip
Make some `match`es exhaustive in `nonterminal.rs`.
For ones matching more than one or two variants, this is easier to think
about.
-rw-r--r--compiler/rustc_parse/src/parser/nonterminal.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs
index fc21c0a8fd6..3862b7640b6 100644
--- a/compiler/rustc_parse/src/parser/nonterminal.rs
+++ b/compiler/rustc_parse/src/parser/nonterminal.rs
@@ -20,7 +20,21 @@ impl<'a> Parser<'a> {
     pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool {
         /// Checks whether the non-terminal may contain a single (non-keyword) identifier.
         fn may_be_ident(nt: &token::Nonterminal) -> bool {
-            !matches!(*nt, NtItem(_) | NtBlock(_) | NtVis(_) | NtLifetime(_))
+            match nt {
+                NtStmt(_)
+                | NtPat(_)
+                | NtExpr(_)
+                | NtTy(_)
+                | NtIdent(..)
+                | NtLiteral(_) // `true`, `false`
+                | NtMeta(_)
+                | NtPath(_) => true,
+
+                NtItem(_)
+                | NtBlock(_)
+                | NtVis(_)
+                | NtLifetime(_) => false,
+            }
         }
 
         match kind {
@@ -41,10 +55,11 @@ impl<'a> Parser<'a> {
             },
             NonterminalKind::Block => match &token.kind {
                 token::OpenDelim(Delimiter::Brace) => true,
-                token::Interpolated(nt) => !matches!(
-                    **nt,
-                    NtItem(_) | NtPat(_) | NtTy(_) | NtIdent(..) | NtMeta(_) | NtPath(_) | NtVis(_)
-                ),
+                token::Interpolated(nt) => match **nt {
+                    NtBlock(_) | NtLifetime(_) | NtStmt(_) | NtExpr(_) | NtLiteral(_) => true,
+                    NtItem(_) | NtPat(_) | NtTy(_) | NtIdent(..) | NtMeta(_) | NtPath(_)
+                    | NtVis(_) => false,
+                },
                 _ => false,
             },
             NonterminalKind::Path | NonterminalKind::Meta => match &token.kind {