File tree 3 files changed +22
-5
lines changed
3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -558,9 +558,10 @@ impl Token {
558
558
/// Returns `true` if the token can appear at the start of a const param.
559
559
pub fn can_begin_const_arg ( & self ) -> bool {
560
560
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 ,
562
563
Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
563
- _ => self . can_begin_literal_maybe_minus ( ) ,
564
+ _ => false ,
564
565
}
565
566
}
566
567
@@ -620,6 +621,21 @@ impl Token {
620
621
}
621
622
}
622
623
624
+ pub fn can_begin_string_literal ( & self ) -> bool {
625
+ match self . uninterpolate ( ) . kind {
626
+ Literal ( ..) => true ,
627
+ Interpolated ( ref nt) => match & * * nt {
628
+ NtLiteral ( _) => true ,
629
+ NtExpr ( e) => match & e. kind {
630
+ ast:: ExprKind :: Lit ( _) => true ,
631
+ _ => false ,
632
+ } ,
633
+ _ => false ,
634
+ } ,
635
+ _ => false ,
636
+ }
637
+ }
638
+
623
639
/// A convenience function for matching on identifiers during parsing.
624
640
/// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token
625
641
/// into the regular identifier or lifetime token it refers to,
Original file line number Diff line number Diff line change @@ -1259,7 +1259,7 @@ impl<'a> Parser<'a> {
1259
1259
self . token . is_keyword ( kw:: Unsafe )
1260
1260
&& self . is_keyword_ahead ( 1 , & [ kw:: Extern ] )
1261
1261
&& self . look_ahead (
1262
- 2 + self . look_ahead ( 2 , |t| t. can_begin_literal_maybe_minus ( ) as usize ) ,
1262
+ 2 + self . look_ahead ( 2 , |t| t. can_begin_string_literal ( ) as usize ) ,
1263
1263
|t| t. kind == token:: OpenDelim ( Delimiter :: Brace ) ,
1264
1264
)
1265
1265
}
@@ -2448,7 +2448,7 @@ impl<'a> Parser<'a> {
2448
2448
} )
2449
2449
// `extern ABI fn`
2450
2450
|| self . check_keyword_case ( kw:: Extern , case)
2451
- && self . look_ahead ( 1 , |t| t. can_begin_literal_maybe_minus ( ) )
2451
+ && self . look_ahead ( 1 , |t| t. can_begin_string_literal ( ) )
2452
2452
&& ( self . look_ahead ( 2 , |t| t. is_keyword_case ( kw:: Fn , case) ) ||
2453
2453
// this branch is only for better diagnostic in later, `pub` is not allowed here
2454
2454
( self . may_recover ( )
Original file line number Diff line number Diff line change @@ -939,7 +939,8 @@ impl<'a> Parser<'a> {
939
939
|| self . look_ahead ( dist, |t| {
940
940
t. is_path_start ( ) // e.g. `MY_CONST`;
941
941
|| 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 ( )
943
944
|| t. is_whole_expr ( )
944
945
|| t. is_lifetime ( ) // recover `'a` instead of `'a'`
945
946
|| ( self . may_recover ( ) // recover leading `(`
You can’t perform that action at this time.
0 commit comments