Skip to content

Commit 382b037

Browse files
committed
auto merge of #8037 : graydon/rust/issue-6416, r=cmr
Errors only turn into failures in the parser when you force them.
2 parents 4c4cf00 + c3417b8 commit 382b037

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/libsyntax/parse/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,10 @@ mod test {
384384
span:sp(0,6)})
385385
}
386386

387-
// FIXME (#6416): For some reason, this fails and causes a test failure, even though it's
388-
// marked as `#[should_fail]`.
389-
/*#[should_fail]
387+
#[should_fail]
390388
#[test] fn bad_path_expr_1() {
391389
string_to_expr(@"::abc::def::return");
392-
}*/
390+
}
393391

394392
#[test] fn string_to_tts_1 () {
395393
let (tts,_ps) = string_to_tts_and_sess(@"fn a (b : int) { b; }");

src/libsyntax/util/parser_testing.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,46 @@ pub fn string_to_parser(source_str: @str) -> Parser {
3333
p
3434
}
3535

36+
fn with_error_checking_parse<T>(s: @str, f: &fn(&mut Parser) -> T) -> T {
37+
let mut p = string_to_parser(s);
38+
let x = f(&mut p);
39+
p.abort_if_errors();
40+
x
41+
}
42+
3643
pub fn string_to_crate (source_str : @str) -> @ast::Crate {
37-
string_to_parser(source_str).parse_crate_mod()
44+
do with_error_checking_parse(source_str) |p| {
45+
p.parse_crate_mod()
46+
}
3847
}
3948

4049
// parse a string, return an expr
4150
pub fn string_to_expr (source_str : @str) -> @ast::expr {
42-
string_to_parser(source_str).parse_expr()
51+
do with_error_checking_parse(source_str) |p| {
52+
p.parse_expr()
53+
}
4354
}
4455

4556
// parse a string, return an item
4657
pub fn string_to_item (source_str : @str) -> Option<@ast::item> {
47-
string_to_parser(source_str).parse_item(~[])
58+
do with_error_checking_parse(source_str) |p| {
59+
p.parse_item(~[])
60+
}
4861
}
4962

5063
// parse a string, return an item and the ParseSess
5164
pub fn string_to_item_and_sess (source_str : @str) -> (Option<@ast::item>,@mut ParseSess) {
5265
let (p,ps) = string_to_parser_and_sess(source_str);
53-
(p.parse_item(~[]),ps)
66+
let io = p.parse_item(~[]);
67+
p.abort_if_errors();
68+
(io,ps)
5469
}
5570

5671
// parse a string, return a stmt
5772
pub fn string_to_stmt(source_str : @str) -> @ast::stmt {
58-
string_to_parser(source_str).parse_stmt(~[])
73+
do with_error_checking_parse(source_str) |p| {
74+
p.parse_stmt(~[])
75+
}
5976
}
6077

6178
// parse a string, return a pat. Uses "irrefutable"... which doesn't

0 commit comments

Comments
 (0)