File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 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> {
261261 /// the previous token or None (only stashed sometimes).
262262 pub last_token : Option < Box < token:: Token > > ,
263263 last_token_interpolated : bool ,
264+ last_token_eof : bool ,
264265 pub buffer : [ TokenAndSpan ; 4 ] ,
265266 pub buffer_start : isize ,
266267 pub buffer_end : isize ,
@@ -369,6 +370,7 @@ impl<'a> Parser<'a> {
369370 last_span : span,
370371 last_token : None ,
371372 last_token_interpolated : false ,
373+ last_token_eof : false ,
372374 buffer : [
373375 placeholder. clone ( ) ,
374376 placeholder. clone ( ) ,
@@ -982,6 +984,15 @@ impl<'a> Parser<'a> {
982984
983985 /// Advance the parser by one token
984986 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+
985996 self . last_span = self . span ;
986997 // Stash token for error recovery (sometimes; clone is not necessarily cheap).
987998 self . last_token = if self . token . is_ident ( ) ||
You can’t perform that action at this time.
0 commit comments