Skip to content

Commit 0b03ba1

Browse files
authored
Auto merge of #36502 - TimNN:correct-cancel, r=jseyfried
correctly cancel some errors Fixes #36499. I also (proactively) changed all other calls in `parser.rs` to use `Handler::cancel`.
2 parents d37e54b + 9f4e908 commit 0b03ba1

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/libsyntax/parse/parser.rs

+11-5
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
}
@@ -2386,7 +2392,7 @@ impl<'a> Parser<'a> {
23862392
ex = ExprKind::Lit(P(lit));
23872393
}
23882394
Err(mut err) => {
2389-
err.cancel();
2395+
self.cancel(&mut err);
23902396
let msg = format!("expected expression, found {}",
23912397
self.this_token_descr());
23922398
return Err(self.fatal(&msg));
@@ -3702,7 +3708,7 @@ impl<'a> Parser<'a> {
37023708
}
37033709
}
37043710
Err(mut err) => {
3705-
err.cancel();
3711+
self.cancel(&mut err);
37063712
let msg = format!("expected pattern, found {}", self.this_token_descr());
37073713
return Err(self.fatal(&msg));
37083714
}
@@ -4076,7 +4082,7 @@ impl<'a> Parser<'a> {
40764082
}
40774083
Err(mut e) => {
40784084
self.recover_stmt_(SemiColonMode::Break);
4079-
e.cancel();
4085+
self.cancel(&mut e);
40804086
}
40814087
_ => ()
40824088
}
@@ -4317,7 +4323,7 @@ impl<'a> Parser<'a> {
43174323
let span_hi = match self.parse_ty() {
43184324
Ok(..) => self.span.hi,
43194325
Err(ref mut err) => {
4320-
err.cancel();
4326+
self.cancel(err);
43214327
span_hi
43224328
}
43234329
};
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)