Skip to content

correctly cancel some errors #36502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,12 @@ impl<'a> Parser<'a> {
/// Eat and discard tokens until one of `kets` is encountered. Respects token trees,
/// passes through any errors encountered. Used for error recovery.
pub fn eat_to_tokens(&mut self, kets: &[&token::Token]) {
let handler = self.diagnostic();

self.parse_seq_to_before_tokens(kets,
SeqSep::none(),
|p| p.parse_token_tree(),
|mut e| e.cancel());
|mut e| handler.cancel(&mut e));
}

/// Parse a sequence, including the closing delimiter. The function
Expand Down Expand Up @@ -1040,6 +1042,10 @@ impl<'a> Parser<'a> {
self.sess.span_diagnostic.abort_if_errors();
}

fn cancel(&self, err: &mut DiagnosticBuilder) {
self.sess.span_diagnostic.cancel(err)
}

pub fn diagnostic(&self) -> &'a errors::Handler {
&self.sess.span_diagnostic
}
Expand Down Expand Up @@ -2416,7 +2422,7 @@ impl<'a> Parser<'a> {
ex = ExprKind::Lit(P(lit));
}
Err(mut err) => {
err.cancel();
self.cancel(&mut err);
let msg = format!("expected expression, found {}",
self.this_token_descr());
return Err(self.fatal(&msg));
Expand Down Expand Up @@ -3732,7 +3738,7 @@ impl<'a> Parser<'a> {
}
}
Err(mut err) => {
err.cancel();
self.cancel(&mut err);
let msg = format!("expected pattern, found {}", self.this_token_descr());
return Err(self.fatal(&msg));
}
Expand Down Expand Up @@ -4106,7 +4112,7 @@ impl<'a> Parser<'a> {
}
Err(mut e) => {
self.recover_stmt_(SemiColonMode::Break);
e.cancel();
self.cancel(&mut e);
}
_ => ()
}
Expand Down Expand Up @@ -4347,7 +4353,7 @@ impl<'a> Parser<'a> {
let span_hi = match self.parse_ty() {
Ok(..) => self.span.hi,
Err(ref mut err) => {
err.cancel();
self.cancel(err);
span_hi
}
};
Expand Down
15 changes: 15 additions & 0 deletions src/test/compile-fail/associated-types/issue-36499.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: aborting due to previous error

fn main() {
2 + +2;
}