File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ pub struct Parser<'a> {
261
261
/// the previous token or None (only stashed sometimes).
262
262
pub last_token : Option < Box < token:: Token > > ,
263
263
last_token_interpolated : bool ,
264
+ last_token_eof : bool ,
264
265
pub buffer : [ TokenAndSpan ; 4 ] ,
265
266
pub buffer_start : isize ,
266
267
pub buffer_end : isize ,
@@ -369,6 +370,7 @@ impl<'a> Parser<'a> {
369
370
last_span : span,
370
371
last_token : None ,
371
372
last_token_interpolated : false ,
373
+ last_token_eof : false ,
372
374
buffer : [
373
375
placeholder. clone ( ) ,
374
376
placeholder. clone ( ) ,
@@ -982,6 +984,15 @@ impl<'a> Parser<'a> {
982
984
983
985
/// Advance the parser by one token
984
986
pub fn bump ( & mut self ) {
987
+ if self . last_token_eof {
988
+ // Bumping after EOF is a bad sign, usually an infinite loop.
989
+ self . bug ( "attempted to bump the parser past EOF (may be stuck in a loop)" ) ;
990
+ }
991
+
992
+ if self . token == token:: Eof {
993
+ self . last_token_eof = true ;
994
+ }
995
+
985
996
self . last_span = self . span ;
986
997
// Stash token for error recovery (sometimes; clone is not necessarily cheap).
987
998
self . last_token = if self . token . is_ident ( ) ||
You can’t perform that action at this time.
0 commit comments