diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 2db3fde13efb..c4f368a4a2f4 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -9,6 +9,7 @@ import std::either; import std::either::left; import std::either::right; import std::map::hashmap; +import token::can_begin_expr; import driver::session; import util::common; import util::common::filename; @@ -120,7 +121,6 @@ fn new_parser(session::session sess, ast::crate_cfg cfg, ext::syntax_expander_table()); } - // These are the words that shouldn't be allowed as value identifiers, // because, if used at the start of a line, they will cause the line to be // interpreted as a specific kind of statement, which would be confusing. @@ -841,14 +841,13 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { lo = ex_ext.span.lo; ex = ex_ext.node; } else if (eat_word(p, "fail")) { - alt (p.peek()) { - case (token::SEMI) { ex = ast::expr_fail(none) } - case (token::RBRACE) { ex = ast::expr_fail(none) } - case (_) { - auto e = parse_expr(p); - hi = e.span.hi; - ex = ast::expr_fail(some(e)); - } + if (can_begin_expr(p.peek())) { + auto e = parse_expr(p); + hi = e.span.hi; + ex = ast::expr_fail(some(e)); + } + else { + ex = ast::expr_fail(none); } } else if (eat_word(p, "log")) { auto e = parse_expr(p); diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index b41553c385bd..44cab2120a02 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -5682,6 +5682,11 @@ fn trans_args(&@block_ctxt cx, ValueRef llenv, &option::t[ValueRef] llobj, auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, cx.sp, args); auto i = 0u; for (@ast::expr e in es) { + if (bcx.build.is_terminated()) { + // This means an earlier arg was divergent. + // So this arg can't be evaluated. + break; + } auto r = trans_arg_expr(bcx, args.(i), arg_tys.(i), e); bcx = r.bcx; llargs += [r.val]; diff --git a/src/test/run-fail/args-fail.rs b/src/test/run-fail/args-fail.rs new file mode 100644 index 000000000000..07f47e0da849 --- /dev/null +++ b/src/test/run-fail/args-fail.rs @@ -0,0 +1,9 @@ +// xfail-stage0 +// error-pattern:meep +fn f(int a, int b, @int c) { + fail "moop"; +} + +fn main() { + f(1, fail "meep", @42); +} \ No newline at end of file