diff options
| author | bors <bors@rust-lang.org> | 2015-12-12 14:35:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-12-12 14:35:43 +0000 |
| commit | 45a73c8c0cf2d5a181be2c1e927212975e0cffc7 (patch) | |
| tree | ae9531561f3d9e3334e4f44c777b9b01bd0f0613 | |
| parent | f0ed9f91690a205dd60a7b27dc01674bd03b87ca (diff) | |
| parent | b85311506dda787216179a438fd2379588f255c6 (diff) | |
| download | rust-45a73c8c0cf2d5a181be2c1e927212975e0cffc7.tar.gz rust-45a73c8c0cf2d5a181be2c1e927212975e0cffc7.zip | |
Auto merge of #30110 - oli-obk:pretty_const_trans, r=pnkfelix
turned some `match`es into `if let`s.
| -rw-r--r-- | src/librustc_trans/trans/consts.rs | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 5284911340b..77664f19aac 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -321,27 +321,26 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, -> Result<ValueRef, ConstEvalFailure> { debug!("get_const_expr_as_global: {:?}", expr.id); // Special-case constants to cache a common global for all uses. - match expr.node { - hir::ExprPath(..) => { - let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def(); - match def { - def::DefConst(def_id) | def::DefAssociatedConst(def_id) => { - if !ccx.tcx().tables.borrow().adjustments.contains_key(&expr.id) { - debug!("get_const_expr_as_global ({:?}): found const {:?}", - expr.id, def_id); - return get_const_val(ccx, def_id, expr); - } + if let hir::ExprPath(..) = expr.node { + // `def` must be its own statement and cannot be in the `match` + // otherwise the `def_map` will be borrowed for the entire match instead + // of just to get the `def` value + let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def(); + match def { + def::DefConst(def_id) | def::DefAssociatedConst(def_id) => { + if !ccx.tcx().tables.borrow().adjustments.contains_key(&expr.id) { + debug!("get_const_expr_as_global ({:?}): found const {:?}", + expr.id, def_id); + return get_const_val(ccx, def_id, expr); } - _ => {} - } + }, + _ => {}, } - _ => {} } let key = (expr.id, param_substs); - match ccx.const_values().borrow().get(&key) { - Some(&val) => return Ok(val), - None => {} + if let Some(&val) = ccx.const_values().borrow().get(&key) { + return Ok(val); } let ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &ccx.tcx().expr_ty(expr)); @@ -350,10 +349,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // references, even when only the latter are correct. try!(const_expr_unadjusted(ccx, expr, ty, param_substs, None, trueconst)) } else { - match const_expr(ccx, expr, param_substs, None, trueconst) { - Err(err) => return Err(err), - Ok((ok, _)) => ok, - } + try!(const_expr(ccx, expr, param_substs, None, trueconst)).0 }; // boolean SSA values are i1, but they have to be stored in i8 slots, @@ -611,9 +607,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, }; let _icx = push_ctxt("const_expr"); Ok(match e.node { - hir::ExprLit(ref lit) => { - const_lit(cx, e, &**lit) - }, + hir::ExprLit(ref lit) => const_lit(cx, e, &**lit), hir::ExprBinary(b, ref e1, ref e2) => { /* Neither type is bottom, and we expect them to be unified * already, so the following is safe. */ |
