From 5854811082a1b3eaf8e168beeffa0d37e6b2407b Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sat, 3 May 2014 23:14:56 +1200 Subject: [PATCH] Refactor `rslt` to `Result::new` --- src/librustc/middle/trans/_match.rs | 22 +++++++++++----------- src/librustc/middle/trans/adt.rs | 10 +++++----- src/librustc/middle/trans/base.rs | 6 +++--- src/librustc/middle/trans/callee.rs | 4 ++-- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 10 ++++++---- src/librustc/middle/trans/datum.rs | 2 +- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 9d8f668a4e1f6..7af61542130ca 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -340,16 +340,16 @@ fn trans_opt<'a>(bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> { let lit_datum = unpack_datum!(bcx, expr::trans(bcx, lit_expr)); let lit_datum = lit_datum.assert_rvalue(bcx); // literals are rvalues let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx)); - return single_result(rslt(bcx, lit_datum.val)); + return single_result(Result::new(bcx, lit_datum.val)); } lit(UnitLikeStructLit(pat_id)) => { let struct_ty = ty::node_id_to_type(bcx.tcx(), pat_id); let datum = datum::rvalue_scratch_datum(bcx, struct_ty, ""); - return single_result(rslt(bcx, datum.val)); + return single_result(Result::new(bcx, datum.val)); } lit(ConstLit(lit_id)) => { let (llval, _) = consts::get_const_val(bcx.ccx(), lit_id); - return single_result(rslt(bcx, llval)); + return single_result(Result::new(bcx, llval)); } var(disr_val, ref repr) => { return adt::trans_case(bcx, &**repr, disr_val); @@ -357,13 +357,13 @@ fn trans_opt<'a>(bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> { range(l1, l2) => { let (l1, _) = consts::const_expr(ccx, l1, true); let (l2, _) = consts::const_expr(ccx, l2, true); - return range_result(rslt(bcx, l1), rslt(bcx, l2)); + return range_result(Result::new(bcx, l1), Result::new(bcx, l2)); } vec_len(n, vec_len_eq, _) => { - return single_result(rslt(bcx, C_int(ccx, n as int))); + return single_result(Result::new(bcx, C_int(ccx, n as int))); } vec_len(n, vec_len_ge(_), _) => { - return lower_bound(rslt(bcx, C_int(ccx, n as int))); + return lower_bound(Result::new(bcx, C_int(ccx, n as int))); } } } @@ -1311,7 +1311,7 @@ fn compare_values<'a>( let _icx = push_ctxt("compare_values"); if ty::type_is_scalar(rhs_t) { let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq); - return rslt(rs.bcx, rs.val); + return Result::new(rs.bcx, rs.val); } match ty::get(rhs_t).sty { @@ -1742,7 +1742,7 @@ fn compile_submatch_continue<'a, 'b>( compare_scalar_types( bcx, test_val, vend, t, ast::BiLe); - rslt(bcx, And(bcx, llge, llle)) + Result::new(bcx, And(bcx, llge, llle)) } } }; @@ -1757,14 +1757,14 @@ fn compile_submatch_continue<'a, 'b>( let value = compare_scalar_values( bcx, test_val, val, signed_int, ast::BiEq); - rslt(bcx, value) + Result::new(bcx, value) } lower_bound( Result {bcx, val: val}) => { let value = compare_scalar_values( bcx, test_val, val, signed_int, ast::BiGe); - rslt(bcx, value) + Result::new(bcx, value) } range_result( Result {val: vbegin, ..}, @@ -1777,7 +1777,7 @@ fn compile_submatch_continue<'a, 'b>( compare_scalar_values( bcx, test_val, vend, signed_int, ast::BiLe); - rslt(bcx, And(bcx, llge, llle)) + Result::new(bcx, And(bcx, llge, llle)) } } }; diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 2791e79907fe1..5046f636e2c6a 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -579,19 +579,19 @@ pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr) -> _match::opt_result<'a> { match *r { CEnum(ity, _, _) => { - _match::single_result(rslt(bcx, C_integral(ll_inttype(bcx.ccx(), ity), - discr as u64, true))) + _match::single_result(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity), + discr as u64, true))) } General(ity, _) => { - _match::single_result(rslt(bcx, C_integral(ll_inttype(bcx.ccx(), ity), - discr as u64, true))) + _match::single_result(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity), + discr as u64, true))) } Univariant(..) => { bcx.ccx().sess().bug("no cases for univariants or structs") } NullablePointer{ .. } => { assert!(discr == 0 || discr == 1); - _match::single_result(rslt(bcx, C_i1(bcx.ccx(), discr != 0))) + _match::single_result(Result::new(bcx, C_i1(bcx.ccx(), discr != 0))) } } } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index daed00a32f21d..cf991325783c5 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -363,7 +363,7 @@ pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>, None); let llty_ptr = type_of::type_of(ccx, ptr_ty); - rslt(r.bcx, PointerCast(r.bcx, r.val, llty_ptr)) + Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr)) } pub fn malloc_raw_dyn_managed<'a>( @@ -393,7 +393,7 @@ pub fn malloc_raw_dyn_managed<'a>( llalign ], None); - rslt(r.bcx, PointerCast(r.bcx, r.val, llty)) + Result::new(r.bcx, PointerCast(r.bcx, r.val, llty)) } // Type descriptor and type glue stuff @@ -543,7 +543,7 @@ pub fn compare_scalar_types<'a>( t: ty::t, op: ast::BinOp) -> Result<'a> { - let f = |a| rslt(cx, compare_scalar_values(cx, lhs, rhs, a, op)); + let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op)); match ty::get(t).sty { ty::ty_nil => f(nil_type), diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index c90ac8a29ef38..37281113978e8 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -746,7 +746,7 @@ pub fn trans_call_inner<'a>( Unreachable(bcx); } - rslt(bcx, llresult) + Result::new(bcx, llresult) } pub enum CallArgs<'a> { @@ -904,5 +904,5 @@ pub fn trans_arg_datum<'a>( } debug!("--- trans_arg_datum passing {}", bcx.val_to_str(val)); - rslt(bcx, val) + Result::new(bcx, val) } diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index a846848f4949a..bfbd638be520c 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -151,7 +151,7 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>, ty::RegionTraitStore(..) => { let cbox_ty = tuplify_box_ty(tcx, cdata_ty); let llbox = alloc_ty(bcx, cbox_ty, "__closure"); - rslt(bcx, llbox) + Result::new(bcx, llbox) } } } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index edb98db416ad3..93baeb71b4307 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -466,10 +466,12 @@ pub struct Result<'a> { pub val: ValueRef } -pub fn rslt<'a>(bcx: &'a Block<'a>, val: ValueRef) -> Result<'a> { - Result { - bcx: bcx, - val: val, +impl<'a> Result<'a> { + pub fn new(bcx: &'a Block<'a>, val: ValueRef) -> Result<'a> { + Result { + bcx: bcx, + val: val, + } } } diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 500a36c5dee60..6af483bce9519 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -679,6 +679,6 @@ impl<'a> DatumBlock<'a, Expr> { pub fn to_llbool(self) -> Result<'a> { let DatumBlock { datum, bcx } = self; - rslt(bcx, datum.to_llbool(bcx)) + Result::new(bcx, datum.to_llbool(bcx)) } }