@@ -424,7 +424,7 @@ impl Token {
424424 NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) => true ,
425425 _ => false ,
426426 } ,
427- _ => self . can_begin_literal_or_bool ( ) ,
427+ _ => self . can_begin_literal_maybe_minus ( ) ,
428428 }
429429 }
430430
@@ -448,13 +448,22 @@ impl Token {
448448 /// Returns `true` if the token is any literal, a minus (which can prefix a literal,
449449 /// for example a '-42', or one of the boolean idents).
450450 ///
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 {
453455 match self . uninterpolate ( ) . kind {
454456 Literal ( ..) | BinOp ( Minus ) => true ,
455457 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
456458 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+ } ,
458467 _ => false ,
459468 } ,
460469 _ => false ,
0 commit comments