@@ -424,7 +424,7 @@ impl Token {
424
424
NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) => true ,
425
425
_ => false ,
426
426
} ,
427
- _ => self . can_begin_literal_or_bool ( ) ,
427
+ _ => self . can_begin_literal_maybe_minus ( ) ,
428
428
}
429
429
}
430
430
@@ -448,13 +448,22 @@ impl Token {
448
448
/// Returns `true` if the token is any literal, a minus (which can prefix a literal,
449
449
/// for example a '-42', or one of the boolean idents).
450
450
///
451
- /// Keep this in sync with `Lit::from_token`.
452
- pub fn can_begin_literal_or_bool ( & self ) -> bool {
451
+ /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
452
+ ///
453
+ /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
454
+ pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
453
455
match self . uninterpolate ( ) . kind {
454
456
Literal ( ..) | BinOp ( Minus ) => true ,
455
457
Ident ( name, false ) if name. is_bool_lit ( ) => true ,
456
458
Interpolated ( ref nt) => match & * * nt {
457
- NtExpr ( e) | NtLiteral ( e) => matches ! ( e. kind, ast:: ExprKind :: Lit ( _) ) ,
459
+ NtLiteral ( _) => true ,
460
+ NtExpr ( e) => match & e. kind {
461
+ ast:: ExprKind :: Lit ( _) => true ,
462
+ ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
463
+ matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
464
+ }
465
+ _ => false ,
466
+ } ,
458
467
_ => false ,
459
468
} ,
460
469
_ => false ,
0 commit comments