about summary refs log tree commit diff
path: root/src/libsyntax/util/parser_testing.rs
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2013-07-25 01:03:53 -0700
committerGraydon Hoare <graydon@mozilla.com>2013-07-25 01:06:38 -0700
commitc3417b88aa20f835a5c19dc5d8539eb33f2802b9 (patch)
tree08641847ed5df67feeed74859c37e41dae54025e /src/libsyntax/util/parser_testing.rs
parentba9c3ebc02716252cf46944e4dd3a866cc51947c (diff)
downloadrust-c3417b88aa20f835a5c19dc5d8539eb33f2802b9.tar.gz
rust-c3417b88aa20f835a5c19dc5d8539eb33f2802b9.zip
syntax: Fix #6416 by aborting on errors after test parse.
Diffstat (limited to 'src/libsyntax/util/parser_testing.rs')
-rw-r--r--src/libsyntax/util/parser_testing.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs
index de97396e453..9d286f1759e 100644
--- a/src/libsyntax/util/parser_testing.rs
+++ b/src/libsyntax/util/parser_testing.rs
@@ -33,29 +33,46 @@ pub fn string_to_parser(source_str: @str) -> Parser {
     p
 }
 
+fn with_error_checking_parse<T>(s: @str, f: &fn(&mut Parser) -> T) -> T {
+    let mut p = string_to_parser(s);
+    let x = f(&mut p);
+    p.abort_if_errors();
+    x
+}
+
 pub fn string_to_crate (source_str : @str) -> @ast::Crate {
-    string_to_parser(source_str).parse_crate_mod()
+    do with_error_checking_parse(source_str) |p| {
+        p.parse_crate_mod()
+    }
 }
 
 // parse a string, return an expr
 pub fn string_to_expr (source_str : @str) -> @ast::expr {
-    string_to_parser(source_str).parse_expr()
+    do with_error_checking_parse(source_str) |p| {
+        p.parse_expr()
+    }
 }
 
 // parse a string, return an item
 pub fn string_to_item (source_str : @str) -> Option<@ast::item> {
-    string_to_parser(source_str).parse_item(~[])
+    do with_error_checking_parse(source_str) |p| {
+        p.parse_item(~[])
+    }
 }
 
 // parse a string, return an item and the ParseSess
 pub fn string_to_item_and_sess (source_str : @str) -> (Option<@ast::item>,@mut ParseSess) {
     let (p,ps) = string_to_parser_and_sess(source_str);
-    (p.parse_item(~[]),ps)
+    let io = p.parse_item(~[]);
+    p.abort_if_errors();
+    (io,ps)
 }
 
 // parse a string, return a stmt
 pub fn string_to_stmt(source_str : @str) -> @ast::stmt {
-    string_to_parser(source_str).parse_stmt(~[])
+    do with_error_checking_parse(source_str) |p| {
+        p.parse_stmt(~[])
+    }
 }
 
 // parse a string, return a pat. Uses "irrefutable"... which doesn't