]> git.lizzy.rs Git - rust.git/commitdiff
Update libsyntax tests.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 24 Oct 2015 03:35:44 +0000 (20:35 -0700)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 28 Oct 2015 03:09:10 +0000 (20:09 -0700)
src/libsyntax/parse/mod.rs
src/libsyntax/util/parser_testing.rs

index 15625cba65c579bcb39f9d8de9ba12d927ef6170..a468f0d1d98f1ae4b762a253d6105cc8d7d0c6d7 100644 (file)
@@ -856,7 +856,7 @@ fn string_to_tts_1() {
 
     #[test] fn parse_stmt_1 () {
         assert!(string_to_stmt("b;".to_string()) ==
-                   P(Spanned{
+                   Some(P(Spanned{
                        node: ast::StmtExpr(P(ast::Expr {
                            id: ast::DUMMY_NODE_ID,
                            node: ast::ExprPath(None, ast::Path {
@@ -871,7 +871,7 @@ fn string_to_tts_1() {
                             }),
                            span: sp(0,1)}),
                                            ast::DUMMY_NODE_ID),
-                       span: sp(0,1)}))
+                       span: sp(0,1)})))
 
     }
 
index 6e6e2d181b9ef195f3b2f16a85052d062557b40c..57138bf26ee069040b9e588b157c03c26ad567ce 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use ast;
-use parse::{ParseSess,filemap_to_tts};
+use parse::{ParseSess,PResult,filemap_to_tts};
 use parse::new_parser_from_source_str;
 use parse::parser::Parser;
 use parse::token;
@@ -31,11 +31,11 @@ pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a>
 }
 
 fn with_error_checking_parse<T, F>(s: String, f: F) -> T where
-    F: FnOnce(&mut Parser) -> T,
+    F: FnOnce(&mut Parser) -> PResult<T>,
 {
     let ps = ParseSess::new();
     let mut p = string_to_parser(&ps, s);
-    let x = f(&mut p);
+    let x = panictry!(f(&mut p));
     p.abort_if_errors();
     x
 }
@@ -43,39 +43,37 @@ fn with_error_checking_parse<T, F>(s: String, f: F) -> T where
 /// Parse a string, return a crate.
 pub fn string_to_crate (source_str : String) -> ast::Crate {
     with_error_checking_parse(source_str, |p| {
-        panictry!(p.parse_crate_mod())
+        p.parse_crate_mod()
     })
 }
 
 /// Parse a string, return an expr
 pub fn string_to_expr (source_str : String) -> P<ast::Expr> {
     with_error_checking_parse(source_str, |p| {
-        p.parse_expr()
+        p.parse_expr_nopanic()
     })
 }
 
 /// Parse a string, return an item
 pub fn string_to_item (source_str : String) -> Option<P<ast::Item>> {
     with_error_checking_parse(source_str, |p| {
-        p.parse_item()
+        p.parse_item_nopanic()
     })
 }
 
 /// Parse a string, return a stmt
-pub fn string_to_stmt(source_str : String) -> P<ast::Stmt> {
+pub fn string_to_stmt(source_str : String) -> Option<P<ast::Stmt>> {
     with_error_checking_parse(source_str, |p| {
-        p.parse_stmt().unwrap()
+        p.parse_stmt_nopanic()
     })
 }
 
 /// Parse a string, return a pat. Uses "irrefutable"... which doesn't
 /// (currently) affect parsing.
 pub fn string_to_pat(source_str: String) -> P<ast::Pat> {
-    // Binding `sess` and `parser` works around dropck-injected
-    // region-inference issues; see #25212, #22323, #22321.
-    let sess = ParseSess::new();
-    let mut parser = string_to_parser(&sess, source_str);
-    parser.parse_pat()
+    with_error_checking_parse(source_str, |p| {
+        p.parse_pat_nopanic()
+    })
 }
 
 /// Convert a vector of strings to a vector of ast::Ident's