about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-06-13 13:40:14 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-06-20 04:50:38 +1000
commit7d9a92ba31122950f2c7f6a71ad6dee49b3e95e4 (patch)
tree14f587f5aec4a62d91a1747efa0630c0d5d92f0a
parent894f7a4ba6554d3797404bbf550d9919df060b97 (diff)
downloadrust-7d9a92ba31122950f2c7f6a71ad6dee49b3e95e4.tar.gz
rust-7d9a92ba31122950f2c7f6a71ad6dee49b3e95e4.zip
Inline `can_begin_literal_maybe_minus` call into two places.
It's clearer this way, because the `Interpolated` cases in
`can_begin_const_arg` and `is_pat_range_end_start` are more permissive
than the `Interpolated` cases in `can_begin_literal_maybe_minus`.
-rw-r--r--compiler/rustc_ast/src/token.rs5
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs3
2 files changed, 5 insertions, 3 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs
index 109c401bb6a..4d513797f5f 100644
--- a/compiler/rustc_ast/src/token.rs
+++ b/compiler/rustc_ast/src/token.rs
@@ -558,9 +558,10 @@ impl Token {
     /// Returns `true` if the token can appear at the start of a const param.
     pub fn can_begin_const_arg(&self) -> bool {
         match self.kind {
-            OpenDelim(Delimiter::Brace) => true,
+            OpenDelim(Delimiter::Brace) | Literal(..) | BinOp(Minus) => true,
+            Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true,
             Interpolated(ref nt) => matches!(&**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
-            _ => self.can_begin_literal_maybe_minus(),
+            _ => false,
         }
     }
 
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 03aea0888d9..6f2b7177159 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -939,7 +939,8 @@ impl<'a> Parser<'a> {
             || self.look_ahead(dist, |t| {
                 t.is_path_start() // e.g. `MY_CONST`;
                 || t.kind == token::Dot // e.g. `.5` for recovery;
-                || t.can_begin_literal_maybe_minus() // e.g. `42`.
+                || matches!(t.kind, token::Literal(..) | token::BinOp(token::Minus))
+                || t.is_bool_lit()
                 || t.is_whole_expr()
                 || t.is_lifetime() // recover `'a` instead of `'a'`
                 || (self.may_recover() // recover leading `(`