Skip to content

Add optional message to fail. #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ tag expr_ {
expr_index(@expr, @expr, ann);
expr_path(path, ann);
expr_ext(path, vec[@expr], option::t[str], @expr, ann);
expr_fail(ann);
expr_fail(ann, option::t[str]);
expr_break(ann);
expr_cont(ann);
expr_ret(option::t[@expr], ann);
Expand Down
15 changes: 12 additions & 3 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ fn parse_value_ident(&parser p) -> ast::ident {
ret parse_ident(p);
}


/* FIXME: gross hack copied from rustboot to make certain configuration-based
* decisions work at build-time. We should probably change it to use a
* lexical sytnax-extension or something similar. For now we just imitate
Expand Down Expand Up @@ -934,7 +933,17 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
ex = expand_syntax_ext(p, ext_span, pth, es.node,
none[str]);
} else if (eat_word(p, "fail")) {
ex = ast::expr_fail(p.get_ann());
auto msg;
alt (p.peek()) {
case (token::LIT_STR(?s)) {
msg = some[str](p.get_str(s));
p.bump();
}
case (_) {
msg = none[str];
}
}
ex = ast::expr_fail(p.get_ann(), msg);
} else if (eat_word(p, "log")) {
auto e = parse_expr(p);
auto hi = e.span.hi;
Expand Down Expand Up @@ -1643,7 +1652,7 @@ fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
case (ast::expr_field(_,_,_)) { ret true; }
case (ast::expr_index(_,_,_)) { ret true; }
case (ast::expr_path(_,_)) { ret true; }
case (ast::expr_fail(_)) { ret true; }
case (ast::expr_fail(_,_)) { ret true; }
case (ast::expr_break(_)) { ret true; }
case (ast::expr_cont(_)) { ret true; }
case (ast::expr_ret(_,_)) { ret true; }
Expand Down
13 changes: 11 additions & 2 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5628,8 +5628,17 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output)
ret trans_expr(cx, expanded);
}

case (ast::expr_fail(_)) {
ret trans_fail(cx, some(e.span), "explicit failure");
case (ast::expr_fail(_, ?str)) {
auto failmsg;
alt (str) {
case (some(?msg)) {
failmsg = msg;
}
case (_) {
failmsg = "explicit failure";
}
}
ret trans_fail(cx, some(e.span), failmsg);
}

case (ast::expr_log(?lvl, ?a, _)) {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/tstate/pre_post_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) -> () {
find_pre_post_expr(fcx, operator);
copy_pre_post(fcx.ccx, a, operator);
}
case (expr_fail(?a)) {
case (expr_fail(?a, _)) {
set_pre_and_post(fcx.ccx, a,
/* if execution continues after fail,
then everything is true! */
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/tstate/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
expr_poststate(fcx.ccx, operand)) || changed;
ret changed;
}
case (expr_fail(?a)) {
case (expr_fail(?a, _)) {
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
/* if execution continues after fail, then everything is true! woo! */
changed = set_poststate_ann(fcx.ccx, a,
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ fn expr_ann(&@ast::expr e) -> ast::ann {
case (ast::expr_index(_,_,?a)) { ret a; }
case (ast::expr_path(_,?a)) { ret a; }
case (ast::expr_ext(_,_,_,_,?a)) { ret a; }
case (ast::expr_fail(?a)) { ret a; }
case (ast::expr_fail(?a,_)) { ret a; }
case (ast::expr_ret(_,?a)) { ret a; }
case (ast::expr_put(_,?a)) { ret a; }
case (ast::expr_be(_,?a)) { ret a; }
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ mod pushdown {
write::ty_only_fixup(fcx, ann.id, t);
}
/* FIXME: should this check the type annotations? */
case (ast::expr_fail(_)) { /* no-op */ }
case (ast::expr_fail(_,_)) { /* no-op */ }
case (ast::expr_log(_,_,_)) { /* no-op */ }
case (ast::expr_break(_)) { /* no-op */ }
case (ast::expr_cont(_)) { /* no-op */ }
Expand Down Expand Up @@ -1972,7 +1972,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
write::ty_only_fixup(fcx, a.id, t);
}

case (ast::expr_fail(?a)) {
case (ast::expr_fail(?a, _)) {
write::bot_ty(fcx.ccx.tcx, a.id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
// Only walk expansion, not args/body.
walk_expr(v, expansion);
}
case (ast::expr_fail(_)) { }
case (ast::expr_fail(_, _)) { }
case (ast::expr_break(_)) { }
case (ast::expr_cont(_)) { }
case (ast::expr_ret(?eo, _)) {
Expand Down
7 changes: 6 additions & 1 deletion src/comp/pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,13 @@ fn print_expr(&ps s, &@ast::expr expr) {
case (ast::expr_path(?path,_)) {
print_path(s, path);
}
case (ast::expr_fail(_)) {
case (ast::expr_fail(_, ?str)) {
word(s.s, "fail");
alt (str) {
case (some(?msg)) {
word(s.s, #fmt("\"%s\"", msg));
}
}
}
case (ast::expr_break(_)) {
word(s.s, "break");
Expand Down
5 changes: 5 additions & 0 deletions src/test/run-fail/explicit-fail-msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:woooo

fn main() {
fail "woooo";
}