Skip to content

Commit 45a73c8

Browse files
committed
Auto merge of rust-lang#30110 - oli-obk:pretty_const_trans, r=pnkfelix
turned some `match`es into `if let`s.
2 parents f0ed9f9 + b853115 commit 45a73c8

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

src/librustc_trans/trans/consts.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -321,27 +321,26 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
321321
-> Result<ValueRef, ConstEvalFailure> {
322322
debug!("get_const_expr_as_global: {:?}", expr.id);
323323
// Special-case constants to cache a common global for all uses.
324-
match expr.node {
325-
hir::ExprPath(..) => {
326-
let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def();
327-
match def {
328-
def::DefConst(def_id) | def::DefAssociatedConst(def_id) => {
329-
if !ccx.tcx().tables.borrow().adjustments.contains_key(&expr.id) {
330-
debug!("get_const_expr_as_global ({:?}): found const {:?}",
331-
expr.id, def_id);
332-
return get_const_val(ccx, def_id, expr);
333-
}
324+
if let hir::ExprPath(..) = expr.node {
325+
// `def` must be its own statement and cannot be in the `match`
326+
// otherwise the `def_map` will be borrowed for the entire match instead
327+
// of just to get the `def` value
328+
let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def();
329+
match def {
330+
def::DefConst(def_id) | def::DefAssociatedConst(def_id) => {
331+
if !ccx.tcx().tables.borrow().adjustments.contains_key(&expr.id) {
332+
debug!("get_const_expr_as_global ({:?}): found const {:?}",
333+
expr.id, def_id);
334+
return get_const_val(ccx, def_id, expr);
334335
}
335-
_ => {}
336-
}
336+
},
337+
_ => {},
337338
}
338-
_ => {}
339339
}
340340

341341
let key = (expr.id, param_substs);
342-
match ccx.const_values().borrow().get(&key) {
343-
Some(&val) => return Ok(val),
344-
None => {}
342+
if let Some(&val) = ccx.const_values().borrow().get(&key) {
343+
return Ok(val);
345344
}
346345
let ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs,
347346
&ccx.tcx().expr_ty(expr));
@@ -350,10 +349,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
350349
// references, even when only the latter are correct.
351350
try!(const_expr_unadjusted(ccx, expr, ty, param_substs, None, trueconst))
352351
} else {
353-
match const_expr(ccx, expr, param_substs, None, trueconst) {
354-
Err(err) => return Err(err),
355-
Ok((ok, _)) => ok,
356-
}
352+
try!(const_expr(ccx, expr, param_substs, None, trueconst)).0
357353
};
358354

359355
// 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>,
611607
};
612608
let _icx = push_ctxt("const_expr");
613609
Ok(match e.node {
614-
hir::ExprLit(ref lit) => {
615-
const_lit(cx, e, &**lit)
616-
},
610+
hir::ExprLit(ref lit) => const_lit(cx, e, &**lit),
617611
hir::ExprBinary(b, ref e1, ref e2) => {
618612
/* Neither type is bottom, and we expect them to be unified
619613
* already, so the following is safe. */

0 commit comments

Comments
 (0)