Skip to content

Commit c81b3fb

Browse files
committed
Merge pull request #12636 from chromatic/fixup_trans_fail
Cleaned up trans_fail(), per eddyb request. Reviewed-by: huonw
2 parents b349fee + e2afa1c commit c81b3fb

File tree

3 files changed

+9
-55
lines changed

3 files changed

+9
-55
lines changed

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ impl<'a> DynamicFailureHandler<'a> {
11881188

11891189
let fcx = self.bcx.fcx;
11901190
let fail_cx = fcx.new_block(false, "case_fallthrough", None);
1191-
controlflow::trans_fail(fail_cx, Some(self.sp), self.msg.clone());
1191+
controlflow::trans_fail(fail_cx, self.sp, self.msg.clone());
11921192
self.finished.set(Some(fail_cx.llbb));
11931193
fail_cx.llbb
11941194
}

src/librustc/middle/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ pub fn fail_if_zero<'a>(
864864
}
865865
};
866866
with_cond(cx, is_zero, |bcx| {
867-
controlflow::trans_fail(bcx, Some(span), InternedString::new(text))
867+
controlflow::trans_fail(bcx, span, InternedString::new(text))
868868
})
869869
}
870870

src/librustc/middle/trans/controlflow.rs

+7-53
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use middle::trans::debuginfo;
1818
use middle::trans::cleanup;
1919
use middle::trans::cleanup::CleanupMethods;
2020
use middle::trans::expr;
21-
use middle::ty;
22-
use util::ppaux;
2321
use util::ppaux::Repr;
2422

2523
use middle::trans::type_::Type;
@@ -327,67 +325,23 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
327325
return bcx;
328326
}
329327

330-
pub fn trans_fail_expr<'a>(
331-
bcx: &'a Block<'a>,
332-
sp_opt: Option<Span>,
333-
fail_expr: Option<@ast::Expr>)
334-
-> &'a Block<'a> {
335-
let _icx = push_ctxt("trans_fail_expr");
336-
let mut bcx = bcx;
337-
match fail_expr {
338-
Some(arg_expr) => {
339-
let ccx = bcx.ccx();
340-
let tcx = ccx.tcx;
341-
let arg_datum =
342-
unpack_datum!(bcx, expr::trans_to_lvalue(bcx, arg_expr, "fail"));
343-
344-
if ty::type_is_str(arg_datum.ty) {
345-
let (lldata, _) = arg_datum.get_vec_base_and_len(bcx);
346-
return trans_fail_value(bcx, sp_opt, lldata);
347-
} else if bcx.unreachable.get() || ty::type_is_bot(arg_datum.ty) {
348-
return bcx;
349-
} else {
350-
bcx.sess().span_bug(
351-
arg_expr.span, ~"fail called with unsupported type " +
352-
ppaux::ty_to_str(tcx, arg_datum.ty));
353-
}
354-
}
355-
_ => trans_fail(bcx, sp_opt, InternedString::new("explicit failure"))
356-
}
357-
}
358-
359328
pub fn trans_fail<'a>(
360329
bcx: &'a Block<'a>,
361-
sp_opt: Option<Span>,
330+
sp: Span,
362331
fail_str: InternedString)
363332
-> &'a Block<'a> {
364-
let _icx = push_ctxt("trans_fail");
365333
let V_fail_str = C_cstr(bcx.ccx(), fail_str);
366-
return trans_fail_value(bcx, sp_opt, V_fail_str);
367-
}
368-
369-
fn trans_fail_value<'a>(
370-
bcx: &'a Block<'a>,
371-
sp_opt: Option<Span>,
372-
V_fail_str: ValueRef)
373-
-> &'a Block<'a> {
374334
let _icx = push_ctxt("trans_fail_value");
375335
let ccx = bcx.ccx();
376-
let (V_filename, V_line) = match sp_opt {
377-
Some(sp) => {
378-
let sess = bcx.sess();
379-
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
380-
(C_cstr(bcx.ccx(), token::intern_and_get_ident(loc.file.name)),
381-
loc.line as int)
382-
}
383-
None => {
384-
(C_cstr(bcx.ccx(), InternedString::new("<runtime>")), 0)
385-
}
386-
};
336+
let sess = bcx.sess();
337+
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
338+
let V_filename = C_cstr(bcx.ccx(),
339+
token::intern_and_get_ident(loc.file.name));
340+
let V_line = loc.line as int;
387341
let V_str = PointerCast(bcx, V_fail_str, Type::i8p());
388342
let V_filename = PointerCast(bcx, V_filename, Type::i8p());
389343
let args = ~[V_str, V_filename, C_int(ccx, V_line)];
390-
let did = langcall(bcx, sp_opt, "", FailFnLangItem);
344+
let did = langcall(bcx, Some(sp), "", FailFnLangItem);
391345
let bcx = callee::trans_lang_call(bcx, did, args, Some(expr::Ignore)).bcx;
392346
Unreachable(bcx);
393347
return bcx;

0 commit comments

Comments
 (0)