Skip to content

Commit 5f95766

Browse files
committed
Remove redundant 'fail' exprs and dead code; use sess.bug or
sess.span_err instead of 'fail'. (issue #444)
1 parent 53ea2a4 commit 5f95766

File tree

4 files changed

+27
-67
lines changed

4 files changed

+27
-67
lines changed

src/comp/middle/resolve.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ fn resolve_names(&@env e, &ast::crate c) {
308308
case (_) {
309309
e.sess.span_err(p.span, "not a tag variant: " +
310310
str::connect(p.node.idents, "::"));
311-
fail;
312311
}
313312
}
314313
for (@ast::pat child in children) {
@@ -412,7 +411,6 @@ fn follow_import(&env e, &list[scope] sc, vec[ident] path, &span sp)
412411
case (_) {
413412
e.sess.span_err(sp, str::connect(path, "::")
414413
+ " does not name a module.");
415-
fail;
416414
}
417415
}
418416
}
@@ -508,12 +506,13 @@ fn lookup_in_scope_strict(&env e, list[scope] sc, &span sp, &ident id,
508506
alt (lookup_in_scope(e, sc, sp, id, ns)) {
509507
case (none) {
510508
unresolved(e, sp, id, ns_name(ns));
511-
fail;
512509
}
513510
case (some(?d)) {
514511
ret d;
515512
}
516513
}
514+
515+
fail; // fools the return-checker
517516
}
518517

519518
fn scope_is_fn(&scope sc) -> bool {
@@ -640,7 +639,6 @@ fn lookup_in_scope(&env e, list[scope] sc, &span sp, &ident id, namespace ns)
640639
}
641640
}
642641
e.sess.bug("reached unreachable code in lookup_in_scope"); // sigh
643-
fail;
644642
}
645643

646644
fn lookup_in_ty_params(&ident id, &vec[ast::ty_param] ty_params)
@@ -790,12 +788,13 @@ fn lookup_in_mod_strict(&env e, def m, &span sp, &ident id,
790788
alt (lookup_in_mod(e, m, sp, id, ns, dr)) {
791789
case (none) {
792790
unresolved(e, sp, id, ns_name(ns));
793-
fail;
794791
}
795792
case (some(?d)) {
796793
ret d;
797794
}
798795
}
796+
797+
fail; // fools the return-checker
799798
}
800799

801800
fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr)
@@ -855,7 +854,7 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
855854
case (ns_module) { md } };
856855
}
857856
}
858-
fail;
857+
fail; // fools the return-checker
859858
}
860859

861860

@@ -915,7 +914,6 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp,
915914
}
916915
e.sess.span_err(sp, "'" + id + "' is glob-imported from" +
917916
" multiple different modules.");
918-
fail;
919917
}
920918
}
921919
// since we don't know what names we have in advance,

src/comp/middle/trans.rs

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ fn type_of(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
715715
cx.sess.span_err (sp,
716716
"type_of() called on a type with dynamic size: " +
717717
ty::ty_to_str(cx.tcx, t));
718-
fail;
719718
}
720719

721720
ret type_of_inner(cx, sp, t);
@@ -937,14 +936,14 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
937936
llty = abs_pair;
938937
}
939938
case (ty::ty_var(_)) {
940-
cx.tcx.sess.span_err(sp, "ty_var in trans::type_of");
939+
cx.tcx.sess.span_err(sp, "trans::type_of called on ty_var");
941940
}
942941
case (ty::ty_param(_)) {
943942
llty = T_i8();
944943
}
945944
case (ty::ty_bound_param(_)) {
946-
log_err "ty_bound_param in trans::type_of";
947-
fail;
945+
cx.tcx.sess.span_err(sp,
946+
"trans::type_of called on ty_bound_param");
948947
}
949948
case (ty::ty_type) { llty = T_ptr(T_tydesc(cx.tn)); }
950949
}
@@ -1212,21 +1211,12 @@ fn find_scope_cx(&@block_ctxt cx) -> @block_ctxt {
12121211
be find_scope_cx(b);
12131212
}
12141213
case (parent_none) {
1215-
fail;
1214+
cx.fcx.lcx.ccx.sess.bug("trans::find_scope_cx() "
1215+
+ "called on parentless block_ctxt");
12161216
}
12171217
}
1218-
}
12191218

1220-
fn find_outer_scope_cx(&@block_ctxt cx) -> @block_ctxt {
1221-
auto scope_cx = find_scope_cx(cx);
1222-
alt (cx.parent) {
1223-
case (parent_some(?b)) {
1224-
be find_scope_cx(b);
1225-
}
1226-
case (parent_none) {
1227-
fail;
1228-
}
1229-
}
1219+
fail; // fools the return-checker
12301220
}
12311221

12321222
fn umax(&@block_ctxt cx, ValueRef a, ValueRef b) -> ValueRef {
@@ -1320,8 +1310,8 @@ fn simplify_type(&@crate_ctxt ccx, &ty::t typ) -> ty::t {
13201310
// Computes the size of the data part of a non-dynamically-sized tag.
13211311
fn static_size_of_tag(&@crate_ctxt cx, &span sp, &ty::t t) -> uint {
13221312
if (ty::type_has_dynamic_size(cx.tcx, t)) {
1323-
log_err "dynamically sized type passed to static_size_of_tag()";
1324-
fail;
1313+
cx.tcx.sess.span_err(sp, "dynamically sized type passed to "
1314+
+ "static_size_of_tag()");
13251315
}
13261316

13271317
if (cx.tag_sizes.contains_key(t)) {
@@ -1336,8 +1326,8 @@ fn static_size_of_tag(&@crate_ctxt cx, &span sp, &ty::t t) -> uint {
13361326
subtys = subtys_;
13371327
}
13381328
case (_) {
1339-
log_err "non-tag passed to static_size_of_tag()";
1340-
fail;
1329+
cx.tcx.sess.span_err(sp, "non-tag passed to "
1330+
+ "static_size_of_tag()");
13411331
}
13421332
}
13431333

@@ -2570,7 +2560,8 @@ fn make_scalar_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
25702560
}
25712561
case (_) {
25722562
// Should never get here, because t is scalar.
2573-
fail;
2563+
cx.fcx.lcx.ccx.sess.bug("non-scalar type passed to "
2564+
+ "make_scalar_cmp_glue");
25742565
}
25752566
}
25762567
}
@@ -2812,7 +2803,6 @@ fn iter_structural_ty_full(&@block_ctxt cx,
28122803
j += 1;
28132804
}
28142805
}
2815-
case (_) { fail; }
28162806
}
28172807

28182808
variant_cx.build.Br(next_cx.llbb);
@@ -2984,7 +2974,6 @@ fn iter_sequence(@block_ctxt cx,
29842974
cx.fcx.lcx.ccx.sess.bug("unexpected type in " +
29852975
"trans::iter_sequence: " +
29862976
ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
2987-
fail;
29882977
}
29892978
}
29902979
}
@@ -3329,7 +3318,6 @@ fn copy_val(&@block_ctxt cx,
33293318

33303319
cx.fcx.lcx.ccx.sess.bug("unexpected type in trans::copy_val: " +
33313320
ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
3332-
fail;
33333321
}
33343322

33353323
// This works like copy_val, except that it deinitializes the source.
@@ -3367,7 +3355,6 @@ fn move_val(&@block_ctxt cx,
33673355

33683356
cx.fcx.lcx.ccx.sess.bug("unexpected type in trans::move_val: " +
33693357
ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
3370-
fail;
33713358
}
33723359

33733360

@@ -3490,12 +3477,11 @@ fn trans_unary(&@block_ctxt cx, ast::unop op,
34903477
ret res(sub.bcx, box);
34913478
}
34923479
case (ast::deref) {
3493-
log_err "deref expressions should have been translated using " +
3494-
"trans_lval(), not trans_unary()";
3495-
fail;
3480+
cx.fcx.lcx.ccx.sess.bug("deref expressions should have been "
3481+
+ "translated using trans_lval(), not "
3482+
+ "trans_unary()");
34963483
}
34973484
}
3498-
fail;
34993485
}
35003486

35013487
fn trans_compare(&@block_ctxt cx0, ast::binop op, &ty::t t0,
@@ -3659,7 +3645,6 @@ fn trans_eager_binop(&@block_ctxt cx, ast::binop op, &ty::t intype,
36593645
ret trans_compare(cx, op, intype, lhs, rhs);
36603646
}
36613647
}
3662-
fail;
36633648
}
36643649

36653650
fn autoderef(&@block_ctxt cx, ValueRef v, &ty::t t) -> result {
@@ -3783,7 +3768,6 @@ fn trans_binary(&@block_ctxt cx, ast::binop op,
37833768
autoderefed_ty(cx.fcx.lcx.ccx, lhty), lhs.val, rhs.val);
37843769
}
37853770
}
3786-
fail;
37873771
}
37883772

37893773
fn join_results(&@block_ctxt parent_cx,
@@ -4211,7 +4195,6 @@ fn trans_for_each(&@block_ctxt cx,
42114195
ret res(r.bcx, C_nil());
42124196
}
42134197
}
4214-
fail;
42154198
}
42164199

42174200

@@ -4325,8 +4308,6 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
43254308
ret res(matched_cx, llval);
43264309
}
43274310
}
4328-
4329-
fail;
43304311
}
43314312

43324313
fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat,
@@ -4650,7 +4631,6 @@ fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0,
46504631
}
46514632
case (_) {cx.fcx.lcx.ccx.sess.unimpl("field variant in trans_field");}
46524633
}
4653-
fail;
46544634
}
46554635

46564636
fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base,
@@ -4747,7 +4727,9 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
47474727
}
47484728
case (_) {
47494729
// Shouldn't happen.
4750-
fail;
4730+
cx.fcx.lcx.ccx.sess.bug(
4731+
"trans_lval called on expr_self_method in a context"
4732+
+ "without llself");
47514733
}
47524734

47534735
}
@@ -4758,7 +4740,6 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
47584740
+ pretty::pprust::expr_to_str(e));
47594741
}
47604742
}
4761-
fail;
47624743
}
47634744

47644745
fn int_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype,
@@ -5898,7 +5879,6 @@ fn trans_log(int lvl, &@block_ctxt cx, &@ast::expr e) -> result {
58985879
cx.fcx.lcx.ccx.sess.span_err(e.span,
58995880
"log called on unsupported type " +
59005881
ty::ty_to_str(cx.fcx.lcx.ccx.tcx, e_ty));
5901-
fail;
59025882
}
59035883
}
59045884
}
@@ -6017,7 +5997,9 @@ fn trans_break_cont(&@block_ctxt cx, bool to_end) -> result {
60175997
}
60185998
}
60195999
}
6020-
fail;
6000+
6001+
// If we get here without returning, it's a bug
6002+
cx.fcx.lcx.ccx.sess.bug("in trans::trans_break_cont()");
60216003
}
60226004

60236005
fn trans_break(&@block_ctxt cx) -> result {
@@ -6085,7 +6067,6 @@ fn trans_port(&@block_ctxt cx, &ast::ann ann) -> result {
60856067
}
60866068
case (_) {
60876069
cx.fcx.lcx.ccx.sess.bug("non-port type in trans_port");
6088-
fail;
60896070
}
60906071
}
60916072

@@ -6310,7 +6291,6 @@ fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
63106291
}
63116292
case (_) {
63126293
bcx.fcx.lcx.ccx.sess.bug("non-chan type in trans_send");
6313-
fail;
63146294
}
63156295
}
63166296

@@ -6432,7 +6412,6 @@ fn trans_anon_obj(&@block_ctxt cx, &span sp,
64326412
// TODO: everything else.
64336413

64346414
cx.fcx.lcx.ccx.sess.unimpl("support for anonymous objects");
6435-
fail;
64366415
}
64376416

64386417
fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
@@ -6917,7 +6896,6 @@ fn arg_tys_of_fn(&@crate_ctxt ccx, ast::ann ann) -> vec[ty::arg] {
69176896
ret arg_tys;
69186897
}
69196898
}
6920-
fail;
69216899
}
69226900

69236901
fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty::t t) -> ty::t {
@@ -6926,7 +6904,6 @@ fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty::t t) -> ty::t {
69266904
ret ret_ty;
69276905
}
69286906
}
6929-
fail;
69306907
}
69316908

69326909

@@ -7515,7 +7492,6 @@ fn decl_fn_and_pair(&@crate_ctxt ccx, &span sp,
75157492
}
75167493
case (_) {
75177494
ccx.sess.bug("decl_fn_and_pair(): fn item doesn't have fn type!");
7518-
fail;
75197495
}
75207496
}
75217497

@@ -7558,7 +7534,6 @@ fn native_fn_ty_param_count(&@crate_ctxt cx, &ast::def_id id) -> uint {
75587534
case (ast::native_item_ty(_,_)) {
75597535
cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " +
75607536
"actually a fn?!");
7561-
fail;
75627537
}
75637538
case (ast::native_item_fn(_, _, _, ?tps, _, _)) {
75647539
count = vec::len[ast::ty_param](tps);
@@ -7574,7 +7549,6 @@ fn native_fn_wrapper_type(&@crate_ctxt cx, &span sp, uint ty_param_count,
75747549
ret type_of_fn(cx, sp, ast::proto_fn, args, out, ty_param_count);
75757550
}
75767551
}
7577-
fail;
75787552
}
75797553

75807554
fn decl_native_fn_and_pair(&@crate_ctxt ccx,
@@ -8013,7 +7987,6 @@ fn find_main_fn(&@crate_ctxt cx) -> ValueRef {
80137987
cx.sess.err("multiple main fns found");
80147988
}
80157989
}
8016-
fail;
80177990
}
80187991

80197992
fn trans_main_fn(@local_ctxt cx, ValueRef crate_map) {

src/comp/middle/ty.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,6 @@ fn field_idx(&session::session sess, &span sp,
18951895
i += 1u;
18961896
}
18971897
sess.span_err(sp, "unknown field '" + id + "' of record");
1898-
fail;
18991898
}
19001899

19011900
fn method_idx(&session::session sess, &span sp,
@@ -1908,7 +1907,6 @@ fn method_idx(&session::session sess, &span sp,
19081907
i += 1u;
19091908
}
19101909
sess.span_err(sp, "unknown method '" + id + "' of obj");
1911-
fail;
19121910
}
19131911

19141912
fn sort_methods(&vec[method] meths) -> vec[method] {
@@ -2904,7 +2902,6 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
29042902
}
29052903
}
29062904
}
2907-
fail; // not reached
29082905
}
29092906

29102907
// Returns information about the tag variant with the given ID:

0 commit comments

Comments
 (0)