@@ -321,27 +321,26 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
321
321
-> Result < ValueRef , ConstEvalFailure > {
322
322
debug ! ( "get_const_expr_as_global: {:?}" , expr. id) ;
323
323
// 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) ;
334
335
}
335
- _ => { }
336
- }
336
+ } ,
337
+ _ => { } ,
337
338
}
338
- _ => { }
339
339
}
340
340
341
341
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) ;
345
344
}
346
345
let ty = monomorphize:: apply_param_substs ( ccx. tcx ( ) , param_substs,
347
346
& ccx. tcx ( ) . expr_ty ( expr) ) ;
@@ -350,10 +349,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
350
349
// references, even when only the latter are correct.
351
350
try!( const_expr_unadjusted ( ccx, expr, ty, param_substs, None , trueconst) )
352
351
} 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
357
353
} ;
358
354
359
355
// 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>,
611
607
} ;
612
608
let _icx = push_ctxt ( "const_expr" ) ;
613
609
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) ,
617
611
hir:: ExprBinary ( b, ref e1, ref e2) => {
618
612
/* Neither type is bottom, and we expect them to be unified
619
613
* already, so the following is safe. */
0 commit comments