Skip to content

Commit 4b63826

Browse files
committed
Replace some explicit fails with 'alt check' invocations
1 parent 5b6eb67 commit 4b63826

File tree

10 files changed

+52
-115
lines changed

10 files changed

+52
-115
lines changed

src/comp/back/link.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,11 @@ mod write {
203203
let LLVMOptAggressive = 3 as c_int; // -O3
204204

205205
let CodeGenOptLevel;
206-
alt opts.optimize {
206+
alt check opts.optimize {
207207
0u { CodeGenOptLevel = LLVMOptNone; }
208208
1u { CodeGenOptLevel = LLVMOptLess; }
209209
2u { CodeGenOptLevel = LLVMOptDefault; }
210210
3u { CodeGenOptLevel = LLVMOptAggressive; }
211-
_ { fail; }
212211
}
213212

214213
let FileType;

src/comp/metadata/csearch.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ fn lookup_defs(cstore: cstore::cstore, cnum: ast::crate_num,
3939
fn lookup_method_purity(cstore: cstore::cstore, did: ast::def_id)
4040
-> ast::purity {
4141
let cdata = cstore::get_crate_data(cstore, did.crate).data;
42-
alt decoder::lookup_def(did.crate, cdata, did) {
42+
alt check decoder::lookup_def(did.crate, cdata, did) {
4343
ast::def_fn(_, p) { p }
44-
_ { fail; }
4544
}
4645
}
4746

src/comp/middle/debuginfo.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)
284284
option::none {}
285285
}
286286

287-
let (name, (size, align), encoding) = alt ty {
287+
let (name, (size, align), encoding) = alt check ty {
288288
ast::ty_bool {("bool", size_and_align_of::<bool>(), DW_ATE_boolean)}
289289
ast::ty_int(m) { alt m {
290290
ast::ty_char {("char", size_and_align_of::<char>(), DW_ATE_unsigned)}
@@ -306,7 +306,6 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)
306306
ast::ty_f32 {("f32", size_and_align_of::<f32>(), DW_ATE_float)}
307307
ast::ty_f64 {("f64", size_and_align_of::<f64>(), DW_ATE_float)}
308308
}}
309-
_ { fail; }
310309
};
311310

312311
let fname = filename_from_span(cx, span);
@@ -511,9 +510,9 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
511510
fn member_size_and_align(tcx: ty::ctxt, ty: @ast::ty) -> (int, int) {
512511
alt ty.node {
513512
ast::ty_path(_, id) {
514-
alt tcx.def_map.get(id) {
513+
alt check tcx.def_map.get(id) {
515514
ast::def_prim_ty(nty) {
516-
alt nty {
515+
alt check nty {
517516
ast::ty_bool { size_and_align_of::<bool>() }
518517
ast::ty_int(m) { alt m {
519518
ast::ty_char { size_and_align_of::<char>() }
@@ -535,10 +534,8 @@ fn member_size_and_align(tcx: ty::ctxt, ty: @ast::ty) -> (int, int) {
535534
ast::ty_f32 { size_and_align_of::<f32>() }
536535
ast::ty_f64 { size_and_align_of::<f64>() }
537536
}}
538-
_ { fail; }
539537
}
540538
}
541-
_ { fail; }
542539
}
543540
}
544541
ast::ty_box(_) | ast::ty_uniq(_) {

src/comp/middle/resolve.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,12 +1965,8 @@ fn find_impls_in_view_item(e: env, vi: @ast::view_item,
19651965
todo(node_id, name, path, span, scopes) {
19661966
resolve_import(e, local_def(node_id), name, *path, span,
19671967
scopes);
1968-
alt e.imports.get(id) {
1968+
alt check e.imports.get(id) {
19691969
resolved(_, _, _, is, _, _) { act(is); }
1970-
_ {
1971-
e.sess.bug("Undocumented invariant in \
1972-
lookup_imported_impls");
1973-
}
19741970
}
19751971
}
19761972
_ {}
@@ -2003,16 +1999,14 @@ fn find_impls_in_view_item(e: env, vi: @ast::view_item,
20031999
}
20042000
}
20052001
ast::view_item_import_glob(ids, id) {
2006-
alt e.imports.get(id) {
2007-
is_glob(path, sc, sp) {
2008-
alt follow_import(e, sc, *path, sp) {
2009-
some(def) { find_impls_in_mod(e, def, impls, none); }
2010-
_ {}
2011-
}
2002+
alt check e.imports.get(id) {
2003+
is_glob(path, sc, sp) {
2004+
alt follow_import(e, sc, *path, sp) {
2005+
some(def) { find_impls_in_mod(e, def, impls, none); }
2006+
_ {}
20122007
}
2013-
_ { e.sess.span_bug(vi.span, "Undocumented invariant in \
2014-
find_impls_in_view_item"); }
20152008
}
2009+
}
20162010
}
20172011
_ {}
20182012
}

src/comp/middle/trans/base.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
22642264
ccx.monomorphized.insert(hash_id, {llfn: lldecl, fty: mono_ty});
22652265

22662266
let psubsts = some({tys: substs, dicts: dicts, bounds: tpt.bounds});
2267-
alt map_node {
2267+
alt check map_node {
22682268
ast_map::node_item(@{node: ast::item_fn(decl, _, body), _}, _) {
22692269
trans_fn(ccx, pt, decl, body, lldecl, no_self, [],
22702270
psubsts, fn_id.node);
@@ -2285,7 +2285,6 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
22852285
trans_fn(ccx, pt, mth.decl, mth.body, lldecl,
22862286
impl_self(selfty), [], psubsts, fn_id.node);
22872287
}
2288-
_ { fail; }
22892288
}
22902289
some({llfn: lldecl, fty: mono_ty})
22912290
}
@@ -2622,15 +2621,14 @@ fn lval_maybe_callee_to_lval(c: lval_maybe_callee, ty: ty::t) -> lval_result {
26222621
add_clean_temp(bcx, space.val, ty);
26232622
{bcx: bcx, val: space.val, kind: temporary}
26242623
} else {
2625-
alt c.env {
2624+
alt check c.env {
26262625
is_closure { {bcx: c.bcx, val: c.val, kind: c.kind} }
26272626
null_env {
26282627
let llfnty = llvm::LLVMGetElementType(val_ty(c.val));
26292628
let llfn = create_real_fn_pair(c.bcx, llfnty, c.val,
26302629
null_env_ptr(c.bcx));
26312630
{bcx: c.bcx, val: llfn, kind: temporary}
26322631
}
2633-
_ { fail; }
26342632
}
26352633
}
26362634
}
@@ -4462,9 +4460,8 @@ fn trans_const(cx: @crate_ctxt, e: @ast::expr, id: ast::node_id) {
44624460
}
44634461

44644462
fn trans_item(ccx: @crate_ctxt, item: ast::item) {
4465-
let path = alt ccx.tcx.items.get(item.id) {
4463+
let path = alt check ccx.tcx.items.get(item.id) {
44664464
ast_map::node_item(_, p) { p }
4467-
_ { fail; }
44684465
};
44694466
alt item.node {
44704467
ast::item_fn(decl, tps, body) {
@@ -4717,8 +4714,8 @@ fn collect_native_item(ccx: @crate_ctxt,
47174714
// For true external functions: create a rust wrapper
47184715
// and link to that. The rust wrapper will handle
47194716
// switching to the C stack.
4720-
let path = *alt ccx.tcx.items.get(i.id) {
4721-
ast_map::node_native_item(_, p) { p } _ { fail; }
4717+
let path = *alt check ccx.tcx.items.get(i.id) {
4718+
ast_map::node_native_item(_, p) { p }
47224719
} + [path_name(i.ident)];
47234720
register_fn(ccx, i.span, path, "native fn", tps, i.id);
47244721
}
@@ -4729,8 +4726,8 @@ fn collect_native_item(ccx: @crate_ctxt,
47294726
}
47304727

47314728
fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
4732-
*alt ccx.tcx.items.get(i.id) {
4733-
ast_map::node_item(_, p) { p } _ { fail; }
4729+
*alt check ccx.tcx.items.get(i.id) {
4730+
ast_map::node_item(_, p) { p }
47344731
} + [path_name(i.ident)]
47354732
}
47364733

src/comp/middle/trans/impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ fn trans_monomorphized_callee(bcx: @block_ctxt, callee_id: ast::node_id,
154154
n_method, n_param, n_bound);
155155
}
156156
let mname = ty::iface_methods(tcx, iface_id)[n_method].ident;
157-
let mth = alt tcx.items.get(impl_did.node) {
157+
let mth = alt check tcx.items.get(impl_did.node) {
158158
ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) {
159159
option::get(vec::find(ms, {|m| m.ident == mname}))
160160
}
161-
_ { fail; }
162161
};
163162
ret trans_static_callee(bcx, callee_id, base,
164163
ast_util::local_def(mth.id),

src/comp/middle/typeck.rs

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
337337
ty::mk_param(tcx, n, id)
338338
}
339339
ast::def_self(iface_id) {
340-
alt tcx.items.get(iface_id.node) {
340+
alt check tcx.items.get(iface_id.node) {
341341
ast_map::node_item(@{node: ast::item_iface(tps, _), _}, _) {
342342
if vec::len(tps) != vec::len(path.node.types) {
343343
tcx.sess.span_err(ast_ty.span, "incorrect number of type \
@@ -347,7 +347,6 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
347347
ast_ty_to_ty(tcx, mode, ast_ty)
348348
}))
349349
}
350-
_ { fail; }
351350
}
352351
}
353352
_ {
@@ -780,13 +779,12 @@ mod collect {
780779
}
781780
}
782781
fn ensure_iface_methods(tcx: ty::ctxt, id: ast::node_id) {
783-
alt tcx.items.get(id) {
782+
alt check tcx.items.get(id) {
784783
ast_map::node_item(@{node: ast::item_iface(_, ms), _}, _) {
785784
ty::store_iface_methods(tcx, id, @vec::map(ms, {|m|
786785
ty_of_ty_method(tcx, m_collect, m)
787786
}));
788787
}
789-
_ { fail; }
790788
}
791789
}
792790
fn convert_class_item(_cx: @ctxt, _parent_ty: ty::t,
@@ -1564,9 +1562,8 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
15641562
alt ccx.method_map.find(callee.id) {
15651563
some(method_static(did)) {
15661564
if did.crate == ast::local_crate {
1567-
alt ccx.tcx.items.get(did.node) {
1565+
alt check ccx.tcx.items.get(did.node) {
15681566
ast_map::node_method(m, _, _) { m.decl.purity }
1569-
_ { fail; }
15701567
}
15711568
} else {
15721569
csearch::lookup_method_purity(ccx.tcx.sess.cstore, did)
@@ -1608,14 +1605,11 @@ fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool {
16081605

16091606
fn impl_self_ty(tcx: ty::ctxt, did: ast::def_id) -> {n_tps: uint, ty: ty::t} {
16101607
if did.crate == ast::local_crate {
1611-
alt tcx.items.get(did.node) {
1608+
alt check tcx.items.get(did.node) {
16121609
ast_map::node_item(@{node: ast::item_impl(ts, _, st, _),
16131610
_}, _) {
16141611
{n_tps: vec::len(ts), ty: ast_ty_to_ty(tcx, m_check, st)}
16151612
}
1616-
an_item {
1617-
tcx.sess.bug("Undocumented invariant in impl_self_ty");
1618-
}
16191613
}
16201614
} else {
16211615
let tpt = csearch::get_type(tcx, did);
@@ -1678,9 +1672,8 @@ fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
16781672
for bound in *tcx.ty_param_bounds.get(did.node) {
16791673
alt bound {
16801674
ty::bound_iface(t) {
1681-
let (iid, tps) = alt ty::get(t).struct {
1675+
let (iid, tps) = alt check ty::get(t).struct {
16821676
ty::ty_iface(i, tps) { (i, tps) }
1683-
_ { fail; }
16841677
};
16851678
let ifce_methods = ty::iface_methods(tcx, iid);
16861679
alt vec::position(*ifce_methods, {|m| m.ident == name}) {
@@ -1727,21 +1720,17 @@ fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
17271720

17281721
fn ty_from_did(tcx: ty::ctxt, did: ast::def_id) -> ty::t {
17291722
if did.crate == ast::local_crate {
1730-
alt tcx.items.get(did.node) {
1723+
alt check tcx.items.get(did.node) {
17311724
ast_map::node_method(m, _, _) {
17321725
let mt = ty_of_method(tcx, m_check, m);
17331726
ty::mk_fn(tcx, {proto: ast::proto_box with mt.fty})
17341727
}
1735-
_ {
1736-
tcx.sess.bug("Undocumented invariant in ty_from_did");
1737-
}
17381728
}
17391729
} else {
1740-
alt ty::get(csearch::get_type(tcx, did).ty).struct {
1730+
alt check ty::get(csearch::get_type(tcx, did).ty).struct {
17411731
ty::ty_fn(fty) {
17421732
ty::mk_fn(tcx, {proto: ast::proto_box with fty})
17431733
}
1744-
_ { fail; }
17451734
}
17461735
}
17471736
}
@@ -2550,22 +2539,16 @@ fn check_decl_initializer(fcx: @fn_ctxt, nid: ast::node_id,
25502539
fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool {
25512540
let bot = false;
25522541

2553-
alt fcx.locals.find(local.node.id) {
2554-
some(i) {
2555-
let t = ty::mk_var(fcx.ccx.tcx, i);
2556-
write_ty(fcx.ccx.tcx, local.node.id, t);
2557-
alt local.node.init {
2558-
some(init) {
2559-
bot = check_decl_initializer(fcx, local.node.id, init);
2560-
}
2561-
_ {/* fall through */ }
2562-
}
2563-
let id_map = pat_util::pat_id_map(fcx.ccx.tcx, local.node.pat);
2564-
check_pat(fcx, id_map, local.node.pat, t);
2542+
let t = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(local.node.id));
2543+
write_ty(fcx.ccx.tcx, local.node.id, t);
2544+
alt local.node.init {
2545+
some(init) {
2546+
bot = check_decl_initializer(fcx, local.node.id, init);
25652547
}
2566-
_ { fcx.ccx.tcx.sess.span_bug(local.span, "Undocumented invariant \
2567-
in check_decl_local"); }
2548+
_ {/* fall through */ }
25682549
}
2550+
let id_map = pat_util::pat_id_map(fcx.ccx.tcx, local.node.pat);
2551+
check_pat(fcx, id_map, local.node.pat, t);
25692552
ret bot;
25702553
}
25712554

@@ -2985,10 +2968,8 @@ mod dict {
29852968
fn lookup_dict(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
29862969
ty: ty::t, iface_ty: ty::t) -> dict_origin {
29872970
let tcx = fcx.ccx.tcx;
2988-
let (iface_id, iface_tps) = alt ty::get(iface_ty).struct {
2971+
let (iface_id, iface_tps) = alt check ty::get(iface_ty).struct {
29892972
ty::ty_iface(did, tps) { (did, tps) }
2990-
_ { tcx.sess.span_bug(sp, "Undocumented invariant in lookup\
2991-
_dict"); }
29922973
};
29932974
let ty = fixup_ty(fcx, sp, ty);
29942975
alt ty::get(ty).struct {
@@ -2997,12 +2978,10 @@ mod dict {
29972978
for bound in *tcx.ty_param_bounds.get(did.node) {
29982979
alt bound {
29992980
ty::bound_iface(ity) {
3000-
alt ty::get(ity).struct {
2981+
alt check ty::get(ity).struct {
30012982
ty::ty_iface(idid, _) {
30022983
if iface_id == idid { ret dict_param(n, n_bound); }
30032984
}
3004-
_ { tcx.sess.span_bug(sp, "Undocumented invariant in \
3005-
lookup_dict"); }
30062985
}
30072986
n_bound += 1u;
30082987
}
@@ -3020,11 +2999,8 @@ mod dict {
30202999
for im in *impls {
30213000
let match = alt ty::impl_iface(tcx, im.did) {
30223001
some(ity) {
3023-
alt ty::get(ity).struct {
3002+
alt check ty::get(ity).struct {
30243003
ty::ty_iface(id, _) { id == iface_id }
3025-
// Bleah, abstract this
3026-
_ { tcx.sess.span_bug(sp, "Undocumented invariant \
3027-
in lookup_dict"); }
30283004
}
30293005
}
30303006
_ { false }
@@ -3086,15 +3062,11 @@ mod dict {
30863062
let tcx = fcx.ccx.tcx;
30873063
let ity = option::get(ty::impl_iface(tcx, impl_did));
30883064
let iface_ty = ty::substitute_type_params(tcx, impl_tys, ity);
3089-
alt ty::get(iface_ty).struct {
3065+
alt check ty::get(iface_ty).struct {
30903066
ty::ty_iface(_, tps) {
30913067
vec::iter2(tps, iface_tys,
30923068
{|a, b| demand::simple(fcx, sp, a, b);});
30933069
}
3094-
_ {
3095-
tcx.sess.span_bug(sp, "Undocumented invariant in \
3096-
connect_iface_tps");
3097-
}
30983070
}
30993071
}
31003072

src/libstd/getopts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ mod tests {
395395
option_missing(_) { assert (ft == option_missing_); }
396396
option_duplicated(_) { assert (ft == option_duplicated_); }
397397
unexpected_argument(_) { assert (ft == unexpected_argument_); }
398-
_ { fail; }
399398
}
400399
}
401400

@@ -406,12 +405,11 @@ mod tests {
406405
let args = ["--test=20"];
407406
let opts = [reqopt("test")];
408407
let rs = getopts(args, opts);
409-
alt rs {
408+
alt check rs {
410409
ok(m) {
411410
assert (opt_present(m, "test"));
412411
assert (opt_str(m, "test") == "20");
413412
}
414-
_ { fail; }
415413
}
416414
}
417415

0 commit comments

Comments
 (0)