Skip to content

Commit 0c25e6f

Browse files
committed
Convert some panics to bug diagnostics in trans
1 parent eb1b500 commit 0c25e6f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/librustc_trans/trans/base.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
301301
self_type.repr(ccx.tcx()));
302302
(&function_type.sig, RustCall, Some(llenvironment_type))
303303
}
304-
_ => panic!("expected closure or fn")
304+
_ => ccx.sess().bug("expected closure or fn")
305305
};
306306

307307
let sig = ty::erase_late_bound_regions(ccx.tcx(), sig);
@@ -2410,12 +2410,15 @@ fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
24102410
node_id: ast::NodeId,
24112411
node_type: Ty<'tcx>)
24122412
-> ValueRef {
2413-
match node_type.sty {
2414-
ty::ty_bare_fn(_, ref f) => {
2415-
assert!(f.abi == Rust || f.abi == RustCall);
2413+
if let ty::ty_bare_fn(_, ref f) = node_type.sty {
2414+
if f.abi != Rust && f.abi != RustCall {
2415+
ccx.sess().span_bug(sp, &format!("only `Rust` or `rust-call` calling conventions \
2416+
are valid for this function, but it uses `{:?}`",
2417+
f.abi.name));
24162418
}
2417-
_ => panic!("expected bare rust fn")
2418-
};
2419+
} else {
2420+
ccx.sess().span_bug(sp, "expected bare rust function")
2421+
}
24192422

24202423
let llfn = decl_rust_fn(ccx, node_type, &sym[..]);
24212424
finish_register_fn(ccx, sp, sym, node_id, llfn);
@@ -2802,7 +2805,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
28022805
llfn
28032806
}
28042807

2805-
_ => panic!("get_item_val: weird result in table")
2808+
_ => ccx.sess().bug("get_item_val: weird result in table")
28062809
};
28072810

28082811
match attr::first_attr_value_str_by_name(&i.attrs,
@@ -2866,7 +2869,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
28662869
let args = match v.node.kind {
28672870
ast::TupleVariantKind(ref args) => args,
28682871
ast::StructVariantKind(_) => {
2869-
panic!("struct variant kind unexpected in get_item_val")
2872+
ccx.sess().bug("struct variant kind unexpected in get_item_val")
28702873
}
28712874
};
28722875
assert!(args.len() != 0);
@@ -2882,7 +2885,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
28822885
ast::ItemEnum(_, _) => {
28832886
register_fn(ccx, (*v).span, sym, id, ty)
28842887
}
2885-
_ => panic!("NodeVariant, shouldn't happen")
2888+
_ => ccx.sess().bug("NodeVariant, shouldn't happen")
28862889
};
28872890
set_inline_hint(llfn);
28882891
llfn

0 commit comments

Comments
 (0)