Skip to content

Commit 9f4e908

Browse files
committed
correctly cancel some errors
1 parent dc75933 commit 9f4e908

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,12 @@ impl<'a> Parser<'a> {
808808
/// Eat and discard tokens until one of `kets` is encountered. Respects token trees,
809809
/// passes through any errors encountered. Used for error recovery.
810810
pub fn eat_to_tokens(&mut self, kets: &[&token::Token]) {
811+
let handler = self.diagnostic();
812+
811813
self.parse_seq_to_before_tokens(kets,
812814
SeqSep::none(),
813815
|p| p.parse_token_tree(),
814-
|mut e| e.cancel());
816+
|mut e| handler.cancel(&mut e));
815817
}
816818

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

1045+
fn cancel(&self, err: &mut DiagnosticBuilder) {
1046+
self.sess.span_diagnostic.cancel(err)
1047+
}
1048+
10431049
pub fn diagnostic(&self) -> &'a errors::Handler {
10441050
&self.sess.span_diagnostic
10451051
}
@@ -2416,7 +2422,7 @@ impl<'a> Parser<'a> {
24162422
ex = ExprKind::Lit(P(lit));
24172423
}
24182424
Err(mut err) => {
2419-
err.cancel();
2425+
self.cancel(&mut err);
24202426
let msg = format!("expected expression, found {}",
24212427
self.this_token_descr());
24222428
return Err(self.fatal(&msg));
@@ -3732,7 +3738,7 @@ impl<'a> Parser<'a> {
37323738
}
37333739
}
37343740
Err(mut err) => {
3735-
err.cancel();
3741+
self.cancel(&mut err);
37363742
let msg = format!("expected pattern, found {}", self.this_token_descr());
37373743
return Err(self.fatal(&msg));
37383744
}
@@ -4106,7 +4112,7 @@ impl<'a> Parser<'a> {
41064112
}
41074113
Err(mut e) => {
41084114
self.recover_stmt_(SemiColonMode::Break);
4109-
e.cancel();
4115+
self.cancel(&mut e);
41104116
}
41114117
_ => ()
41124118
}
@@ -4347,7 +4353,7 @@ impl<'a> Parser<'a> {
43474353
let span_hi = match self.parse_ty() {
43484354
Ok(..) => self.span.hi,
43494355
Err(ref mut err) => {
4350-
err.cancel();
4356+
self.cancel(err);
43514357
span_hi
43524358
}
43534359
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern: aborting due to previous error
12+
13+
fn main() {
14+
2 + +2;
15+
}

0 commit comments

Comments
 (0)