about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-09-17 20:57:05 -0700
committerGitHub <noreply@github.com>2016-09-17 20:57:05 -0700
commit0b03ba1f5545ac1e8c434346de29c41aba82837e (patch)
treeb76bf61ec56005a6c0bdc398b2e8fb8d0f21be68 /src
parentd37e54b419507ee1f264d7778ed12b30ddb21fe5 (diff)
parent9f4e9083604f68c6ee55461687802dfecd753836 (diff)
downloadrust-0b03ba1f5545ac1e8c434346de29c41aba82837e.tar.gz
rust-0b03ba1f5545ac1e8c434346de29c41aba82837e.zip
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`.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/parser.rs16
-rw-r--r--src/test/compile-fail/associated-types/issue-36499.rs15
2 files changed, 26 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 98ceb4fbd6c..93bf800bb14 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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
@@ -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
     }
@@ -2386,7 +2392,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));
@@ -3702,7 +3708,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));
                     }
@@ -4076,7 +4082,7 @@ impl<'a> Parser<'a> {
                 }
                 Err(mut e) => {
                     self.recover_stmt_(SemiColonMode::Break);
-                    e.cancel();
+                    self.cancel(&mut e);
                 }
                 _ => ()
             }
@@ -4317,7 +4323,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
                 }
             };
diff --git a/src/test/compile-fail/associated-types/issue-36499.rs b/src/test/compile-fail/associated-types/issue-36499.rs
new file mode 100644
index 00000000000..b5b3ecbb580
--- /dev/null
+++ b/src/test/compile-fail/associated-types/issue-36499.rs
@@ -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;
+}