Skip to content

Commit 7d9a92b

Browse files
committed
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`.
1 parent 894f7a4 commit 7d9a92b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_ast/src/token.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,10 @@ impl Token {
558558
/// Returns `true` if the token can appear at the start of a const param.
559559
pub fn can_begin_const_arg(&self) -> bool {
560560
match self.kind {
561-
OpenDelim(Delimiter::Brace) => true,
561+
OpenDelim(Delimiter::Brace) | Literal(..) | BinOp(Minus) => true,
562+
Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true,
562563
Interpolated(ref nt) => matches!(&**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
563-
_ => self.can_begin_literal_maybe_minus(),
564+
_ => false,
564565
}
565566
}
566567

compiler/rustc_parse/src/parser/pat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,8 @@ impl<'a> Parser<'a> {
939939
|| self.look_ahead(dist, |t| {
940940
t.is_path_start() // e.g. `MY_CONST`;
941941
|| t.kind == token::Dot // e.g. `.5` for recovery;
942-
|| t.can_begin_literal_maybe_minus() // e.g. `42`.
942+
|| matches!(t.kind, token::Literal(..) | token::BinOp(token::Minus))
943+
|| t.is_bool_lit()
943944
|| t.is_whole_expr()
944945
|| t.is_lifetime() // recover `'a` instead of `'a'`
945946
|| (self.may_recover() // recover leading `(`

0 commit comments

Comments
 (0)