Skip to content

Commit c59ea49

Browse files
committed
librustc_trans: use bug!(), span_bug!()
1 parent 35e1603 commit c59ea49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+436
-484
lines changed

src/librustc_trans/_match.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a> ConstantExpr<'a> {
242242
fn eq(self, other: ConstantExpr<'a>, tcx: &TyCtxt) -> bool {
243243
match compare_lit_exprs(tcx, self.0, other.0) {
244244
Some(result) => result == Ordering::Equal,
245-
None => panic!("compare_list_exprs: type mismatch"),
245+
None => bug!("compare_list_exprs: type mismatch"),
246246
}
247247
}
248248
}
@@ -828,7 +828,7 @@ impl FailureHandler {
828828
fn handle_fail(&self, bcx: Block) {
829829
match *self {
830830
Infallible =>
831-
panic!("attempted to panic in a non-panicking panic handler!"),
831+
bug!("attempted to panic in a non-panicking panic handler!"),
832832
JumpToBasicBlock(basic_block) =>
833833
Br(bcx, basic_block, DebugLoc::None),
834834
Unreachable =>
@@ -939,11 +939,11 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
939939

940940
compare_str(cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc)
941941
},
942-
_ => cx.sess().bug("only byte strings supported in compare_values"),
942+
_ => bug!("only byte strings supported in compare_values"),
943943
},
944-
_ => cx.sess().bug("only string and byte strings supported in compare_values"),
944+
_ => bug!("only string and byte strings supported in compare_values"),
945945
},
946-
_ => cx.sess().bug("only scalars, byte strings, and strings supported in compare_values"),
946+
_ => bug!("only scalars, byte strings, and strings supported in compare_values"),
947947
}
948948
}
949949

@@ -986,7 +986,7 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
986986
Lvalue::new_with_hint("_match::insert_lllocals (match_input)",
987987
bcx, binding_info.id, hint_kind)
988988
}
989-
_ => unreachable!(),
989+
_ => bug!(),
990990
};
991991
let datum = Datum::new(llval, binding_info.ty, lvalue);
992992
call_lifetime_start(bcx, llbinding);
@@ -1317,7 +1317,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
13171317
bcx = r.bcx;
13181318
}
13191319
_ => {
1320-
bcx.sess().bug(
1320+
bug!(
13211321
"in compile_submatch, expected \
13221322
opt.trans() to return a SingleResult")
13231323
}

src/librustc_trans/abi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl FnType {
218218
Rust | RustCall => llvm::CCallConv,
219219

220220
// It's the ABI's job to select this, not us.
221-
System => ccx.sess().bug("system abi should be selected elsewhere"),
221+
System => bug!("system abi should be selected elsewhere"),
222222

223223
Stdcall => llvm::X86StdcallCallConv,
224224
Fastcall => llvm::X86FastcallCallConv,
@@ -241,8 +241,8 @@ impl FnType {
241241
&tupled_arguments[..]
242242
}
243243
_ => {
244-
unreachable!("argument to function with \"rust-call\" ABI \
245-
is not a tuple");
244+
bug!("argument to function with \"rust-call\" ABI \
245+
is not a tuple");
246246
}
247247
}
248248
} else {

src/librustc_trans/adt.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
302302
// non-empty body, explicit discriminants should have
303303
// been rejected by a checker before this point.
304304
if !cases.iter().enumerate().all(|(i,c)| c.discr == Disr::from(i)) {
305-
cx.sess().bug(&format!("non-C-like enum {} with specified \
306-
discriminants",
307-
cx.tcx().item_path_str(def.did)));
305+
bug!("non-C-like enum {} with specified discriminants",
306+
cx.tcx().item_path_str(def.did));
308307
}
309308

310309
if cases.len() == 1 {
@@ -430,7 +429,7 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
430429

431430
General(ity, fields, dtor_to_init_u8(dtor))
432431
}
433-
_ => cx.sess().bug(&format!("adt::represent_type called on non-ADT type: {}", t))
432+
_ => bug!("adt::represent_type called on non-ADT type: {}", t)
434433
}
435434
}
436435

@@ -615,7 +614,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
615614
match hint {
616615
attr::ReprInt(span, ity) => {
617616
if !bounds_usable(cx, ity, bounds) {
618-
cx.sess().span_bug(span, "representation hint insufficient for discriminant range")
617+
span_bug!(span, "representation hint insufficient for discriminant range")
619618
}
620619
return ity;
621620
}
@@ -632,10 +631,10 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
632631
attempts = choose_shortest;
633632
},
634633
attr::ReprPacked => {
635-
cx.tcx().sess.bug("range_to_inttype: found ReprPacked on an enum");
634+
bug!("range_to_inttype: found ReprPacked on an enum");
636635
}
637636
attr::ReprSimd => {
638-
cx.tcx().sess.bug("range_to_inttype: found ReprSimd on an enum");
637+
bug!("range_to_inttype: found ReprSimd on an enum");
639638
}
640639
}
641640
for &ity in attempts {
@@ -835,7 +834,7 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
835834
Type::array(&Type::i64(cx), align_units),
836835
a if a.count_ones() == 1 => Type::array(&Type::vector(&Type::i32(cx), a / 4),
837836
align_units),
838-
_ => panic!("unsupported enum alignment: {}", align)
837+
_ => bug!("unsupported enum alignment: {}", align)
839838
};
840839
assert_eq!(machine::llalign_of_min(cx, fill_ty), align);
841840
assert_eq!(padded_discr_size % discr_size, 0); // Ensure discr_ty can fill pad evenly
@@ -984,7 +983,7 @@ pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr)
984983
C_integral(ll_inttype(bcx.ccx(), ity), discr.0, true)
985984
}
986985
Univariant(..) => {
987-
bcx.ccx().sess().bug("no cases for univariants or structs")
986+
bug!("no cases for univariants or structs")
988987
}
989988
RawNullablePointer { .. } |
990989
StructWrappedNullablePointer { .. } => {
@@ -1088,7 +1087,7 @@ pub fn trans_field_ptr_builder<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
10881087
// someday), it will need to return a possibly-new bcx as well.
10891088
match *r {
10901089
CEnum(..) => {
1091-
bcx.ccx().sess().bug("element access in C-like enum")
1090+
bug!("element access in C-like enum")
10921091
}
10931092
Univariant(ref st, _dtor) => {
10941093
assert_eq!(discr, Disr(0));
@@ -1279,7 +1278,7 @@ pub fn fold_variants<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
12791278

12801279
bcx_next
12811280
}
1282-
_ => unreachable!()
1281+
_ => bug!()
12831282
}
12841283
}
12851284

@@ -1319,7 +1318,7 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
13191318
fcx.pop_custom_cleanup_scope(custom_cleanup_scope);
13201319
datum::DatumBlock::new(bcx, expr_datum)
13211320
}
1322-
_ => bcx.ccx().sess().bug("tried to get drop flag of non-droppable type")
1321+
_ => bug!("tried to get drop flag of non-droppable type")
13231322
}
13241323
}
13251324

@@ -1478,7 +1477,7 @@ pub fn const_get_discrim(r: &Repr, val: ValueRef) -> Disr {
14781477
}
14791478
Univariant(..) => Disr(0),
14801479
RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => {
1481-
unreachable!("const discrim access of non c-like enum")
1480+
bug!("const discrim access of non c-like enum")
14821481
}
14831482
}
14841483
}
@@ -1488,10 +1487,10 @@ pub fn const_get_discrim(r: &Repr, val: ValueRef) -> Disr {
14881487
///
14891488
/// (Not to be confused with `common::const_get_elt`, which operates on
14901489
/// raw LLVM-level structs and arrays.)
1491-
pub fn const_get_field(ccx: &CrateContext, r: &Repr, val: ValueRef,
1492-
_discr: Disr, ix: usize) -> ValueRef {
1490+
pub fn const_get_field(r: &Repr, val: ValueRef, _discr: Disr,
1491+
ix: usize) -> ValueRef {
14931492
match *r {
1494-
CEnum(..) => ccx.sess().bug("element access in C-like enum const"),
1493+
CEnum(..) => bug!("element access in C-like enum const"),
14951494
Univariant(..) => const_struct_field(val, ix),
14961495
General(..) => const_struct_field(val, ix + 1),
14971496
RawNullablePointer { .. } => {

src/librustc_trans/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn dump_graph(tcx: &TyCtxt) {
221221
// Expect one of: "-> target", "source -> target", or "source ->".
222222
let parts: Vec<_> = string.split("->").collect();
223223
if parts.len() > 2 {
224-
panic!("Invalid RUST_DEP_GRAPH_FILTER: expected '[source] -> [target]'");
224+
bug!("Invalid RUST_DEP_GRAPH_FILTER: expected '[source] -> [target]'");
225225
}
226226
let sources = node_set(&query, &parts[0]);
227227
let targets = node_set(&query, &parts[1]);

src/librustc_trans/back/link.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ pub fn link_binary(sess: &Session,
187187
let mut out_filenames = Vec::new();
188188
for &crate_type in sess.crate_types.borrow().iter() {
189189
if invalid_output_for_target(sess, crate_type) {
190-
sess.bug(&format!("invalid output type `{:?}` for target os `{}`",
191-
crate_type, sess.opts.target_triple));
190+
bug!("invalid output type `{:?}` for target os `{}`",
191+
crate_type, sess.opts.target_triple);
192192
}
193193
let out_file = link_binary_output(sess, trans, crate_type, outputs,
194194
crate_name);
@@ -282,7 +282,7 @@ pub fn each_linked_rlib(sess: &Session,
282282
let fmts = fmts.get(&config::CrateTypeExecutable).or_else(|| {
283283
fmts.get(&config::CrateTypeStaticlib)
284284
}).unwrap_or_else(|| {
285-
sess.bug("could not find formats for rlibs")
285+
bug!("could not find formats for rlibs")
286286
});
287287
for (cnum, path) in crates {
288288
match fmts[cnum as usize - 1] {
@@ -895,7 +895,7 @@ fn add_local_native_libraries(cmd: &mut Linker, sess: &Session) {
895895
match kind {
896896
NativeLibraryKind::NativeUnknown => cmd.link_dylib(l),
897897
NativeLibraryKind::NativeFramework => cmd.link_framework(l),
898-
NativeLibraryKind::NativeStatic => unreachable!(),
898+
NativeLibraryKind::NativeStatic => bug!(),
899899
}
900900
}
901901
}
@@ -1081,7 +1081,7 @@ fn add_upstream_native_libraries(cmd: &mut Linker, sess: &Session) {
10811081
NativeLibraryKind::NativeUnknown => cmd.link_dylib(lib),
10821082
NativeLibraryKind::NativeFramework => cmd.link_framework(lib),
10831083
NativeLibraryKind::NativeStatic => {
1084-
sess.bug("statics shouldn't be propagated");
1084+
bug!("statics shouldn't be propagated");
10851085
}
10861086
}
10871087
}

src/librustc_trans/back/linker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ impl<'a> Linker for MsvcLinker<'a> {
271271
}
272272

273273
fn framework_path(&mut self, _path: &Path) {
274-
panic!("frameworks are not supported on windows")
274+
bug!("frameworks are not supported on windows")
275275
}
276276
fn link_framework(&mut self, _framework: &str) {
277-
panic!("frameworks are not supported on windows")
277+
bug!("frameworks are not supported on windows")
278278
}
279279

280280
fn link_whole_staticlib(&mut self, lib: &str, _search_path: &[PathBuf]) {

src/librustc_trans/back/symbol_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ fn exported_name_with_opt_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
224224
// to be a value or type-def or something in there
225225
// *somewhere*
226226
ty_def_id.index = key.parent.unwrap_or_else(|| {
227-
panic!("finding type for {:?}, encountered def-id {:?} with no \
228-
parent", def_id, ty_def_id);
227+
bug!("finding type for {:?}, encountered def-id {:?} with no \
228+
parent", def_id, ty_def_id);
229229
});
230230
}
231231
}

src/librustc_trans/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Emitter for SharedEmitter {
113113
}
114114

115115
fn custom_emit(&mut self, _sp: &errors::RenderSpan, _msg: &str, _lvl: Level) {
116-
panic!("SharedEmitter doesn't support custom_emit");
116+
bug!("SharedEmitter doesn't support custom_emit");
117117
}
118118
}
119119

@@ -159,7 +159,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
159159
.cg
160160
.relocation_model));
161161
sess.abort_if_errors();
162-
unreachable!();
162+
bug!();
163163
}
164164
};
165165

@@ -190,7 +190,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
190190
.cg
191191
.code_model));
192192
sess.abort_if_errors();
193-
unreachable!();
193+
bug!();
194194
}
195195
};
196196

0 commit comments

Comments
 (0)