Skip to content

Commit 56ba8fe

Browse files
committed
Update libsyntax tests.
1 parent e502492 commit 56ba8fe

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/libsyntax/parse/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ mod tests {
856856

857857
#[test] fn parse_stmt_1 () {
858858
assert!(string_to_stmt("b;".to_string()) ==
859-
P(Spanned{
859+
Some(P(Spanned{
860860
node: ast::StmtExpr(P(ast::Expr {
861861
id: ast::DUMMY_NODE_ID,
862862
node: ast::ExprPath(None, ast::Path {
@@ -871,7 +871,7 @@ mod tests {
871871
}),
872872
span: sp(0,1)}),
873873
ast::DUMMY_NODE_ID),
874-
span: sp(0,1)}))
874+
span: sp(0,1)})))
875875

876876
}
877877

src/libsyntax/util/parser_testing.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use ast;
12-
use parse::{ParseSess,filemap_to_tts};
12+
use parse::{ParseSess,PResult,filemap_to_tts};
1313
use parse::new_parser_from_source_str;
1414
use parse::parser::Parser;
1515
use parse::token;
@@ -31,51 +31,49 @@ pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a>
3131
}
3232

3333
fn with_error_checking_parse<T, F>(s: String, f: F) -> T where
34-
F: FnOnce(&mut Parser) -> T,
34+
F: FnOnce(&mut Parser) -> PResult<T>,
3535
{
3636
let ps = ParseSess::new();
3737
let mut p = string_to_parser(&ps, s);
38-
let x = f(&mut p);
38+
let x = panictry!(f(&mut p));
3939
p.abort_if_errors();
4040
x
4141
}
4242

4343
/// Parse a string, return a crate.
4444
pub fn string_to_crate (source_str : String) -> ast::Crate {
4545
with_error_checking_parse(source_str, |p| {
46-
panictry!(p.parse_crate_mod())
46+
p.parse_crate_mod()
4747
})
4848
}
4949

5050
/// Parse a string, return an expr
5151
pub fn string_to_expr (source_str : String) -> P<ast::Expr> {
5252
with_error_checking_parse(source_str, |p| {
53-
p.parse_expr()
53+
p.parse_expr_nopanic()
5454
})
5555
}
5656

5757
/// Parse a string, return an item
5858
pub fn string_to_item (source_str : String) -> Option<P<ast::Item>> {
5959
with_error_checking_parse(source_str, |p| {
60-
p.parse_item()
60+
p.parse_item_nopanic()
6161
})
6262
}
6363

6464
/// Parse a string, return a stmt
65-
pub fn string_to_stmt(source_str : String) -> P<ast::Stmt> {
65+
pub fn string_to_stmt(source_str : String) -> Option<P<ast::Stmt>> {
6666
with_error_checking_parse(source_str, |p| {
67-
p.parse_stmt().unwrap()
67+
p.parse_stmt_nopanic()
6868
})
6969
}
7070

7171
/// Parse a string, return a pat. Uses "irrefutable"... which doesn't
7272
/// (currently) affect parsing.
7373
pub fn string_to_pat(source_str: String) -> P<ast::Pat> {
74-
// Binding `sess` and `parser` works around dropck-injected
75-
// region-inference issues; see #25212, #22323, #22321.
76-
let sess = ParseSess::new();
77-
let mut parser = string_to_parser(&sess, source_str);
78-
parser.parse_pat()
74+
with_error_checking_parse(source_str, |p| {
75+
p.parse_pat_nopanic()
76+
})
7977
}
8078

8179
/// Convert a vector of strings to a vector of ast::Ident's

0 commit comments

Comments
 (0)