Skip to content

Commit

Permalink
Don't loop forever on error recovery with EOF
Browse files Browse the repository at this point in the history
closes #31804
  • Loading branch information
nrc committed Mar 22, 2016
1 parent e3f2dfd commit 3ee841c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3824,7 +3824,9 @@ impl<'a> Parser<'a> {
fn recover_stmt_(&mut self, break_on_semi: SemiColonMode) {
let mut brace_depth = 0;
let mut bracket_depth = 0;
debug!("recover_stmt_ enter loop");
loop {
debug!("recover_stmt_ loop {:?}", self.token);
match self.token {
token::OpenDelim(token::DelimToken::Brace) => {
brace_depth += 1;
Expand All @@ -3836,6 +3838,7 @@ impl<'a> Parser<'a> {
}
token::CloseDelim(token::DelimToken::Brace) => {
if brace_depth == 0 {
debug!("recover_stmt_ return - close delim {:?}", self.token);
return;
}
brace_depth -= 1;
Expand All @@ -3848,12 +3851,16 @@ impl<'a> Parser<'a> {
}
self.bump();
}
token::Eof => return,
token::Eof => {
debug!("recover_stmt_ return - Eof");
return;
}
token::Semi => {
self.bump();
if break_on_semi == SemiColonMode::Break &&
brace_depth == 0 &&
bracket_depth == 0 {
debug!("recover_stmt_ return - Semi");
return;
}
}
Expand Down Expand Up @@ -4042,6 +4049,8 @@ impl<'a> Parser<'a> {
while !self.eat(&token::CloseDelim(token::Brace)) {
let Spanned {node, span} = if let Some(s) = self.parse_stmt_() {
s
} else if self.token == token::Eof {
break;
} else {
// Found only `;` or `}`.
continue;
Expand Down

0 comments on commit 3ee841c

Please sign in to comment.