@@ -287,27 +287,26 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
287287 -> Result < ValueRef , ConstEvalFailure > {
288288 debug ! ( "get_const_expr_as_global: {:?}" , expr. id) ;
289289 // Special-case constants to cache a common global for all uses.
290- match expr. node {
291- hir:: ExprPath ( ..) => {
292- let def = ccx. tcx ( ) . def_map . borrow ( ) . get ( & expr. id ) . unwrap ( ) . full_def ( ) ;
293- match def {
294- def:: DefConst ( def_id) | def:: DefAssociatedConst ( def_id) => {
295- if !ccx. tcx ( ) . tables . borrow ( ) . adjustments . contains_key ( & expr. id ) {
296- debug ! ( "get_const_expr_as_global ({:?}): found const {:?}" ,
297- expr. id, def_id) ;
298- return get_const_val ( ccx, def_id, expr) ;
299- }
290+ if let hir:: ExprPath ( ..) = expr. node {
291+ // `def` must be its own statement and cannot be in the `match`
292+ // otherwise the `def_map` will be borrowed for the entire match instead
293+ // of just to get the `def` value
294+ let def = ccx. tcx ( ) . def_map . borrow ( ) . get ( & expr. id ) . unwrap ( ) . full_def ( ) ;
295+ match def {
296+ def:: DefConst ( def_id) | def:: DefAssociatedConst ( def_id) => {
297+ if !ccx. tcx ( ) . tables . borrow ( ) . adjustments . contains_key ( & expr. id ) {
298+ debug ! ( "get_const_expr_as_global ({:?}): found const {:?}" ,
299+ expr. id, def_id) ;
300+ return get_const_val ( ccx, def_id, expr) ;
300301 }
301- _ => { }
302- }
302+ } ,
303+ _ => { } ,
303304 }
304- _ => { }
305305 }
306306
307307 let key = ( expr. id , param_substs) ;
308- match ccx. const_values ( ) . borrow ( ) . get ( & key) {
309- Some ( & val) => return Ok ( val) ,
310- None => { }
308+ if let Some ( & val) = ccx. const_values ( ) . borrow ( ) . get ( & key) {
309+ return Ok ( val) ;
311310 }
312311 let ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs,
313312 & ccx. tcx ( ) . expr_ty ( expr) ) ;
@@ -316,10 +315,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
316315 // references, even when only the latter are correct.
317316 try!( const_expr_unadjusted ( ccx, expr, ty, param_substs, None , trueconst) )
318317 } else {
319- match const_expr ( ccx, expr, param_substs, None , trueconst) {
320- Err ( err) => return Err ( err) ,
321- Ok ( ( ok, _) ) => ok,
322- }
318+ try!( const_expr ( ccx, expr, param_substs, None , trueconst) ) . 0
323319 } ;
324320
325321 // boolean SSA values are i1, but they have to be stored in i8 slots,
@@ -577,9 +573,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
577573 } ;
578574 let _icx = push_ctxt ( "const_expr" ) ;
579575 Ok ( match e. node {
580- hir:: ExprLit ( ref lit) => {
581- const_lit ( cx, e, & * * lit)
582- } ,
576+ hir:: ExprLit ( ref lit) => const_lit ( cx, e, & * * lit) ,
583577 hir:: ExprBinary ( b, ref e1, ref e2) => {
584578 /* Neither type is bottom, and we expect them to be unified
585579 * already, so the following is safe. */
0 commit comments