@@ -121,8 +121,12 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
121
121
122
122
// Check that we do not match against a static NaN (#6804)
123
123
let pat_matches_nan: |& Pat | -> bool = |p| {
124
- match cx. tcx . def_map . find ( & p. id ) {
125
- Some ( & DefStatic ( did, false ) ) => {
124
+ let opt_def = {
125
+ let def_map = cx. tcx . def_map . borrow ( ) ;
126
+ def_map. get ( ) . find_copy ( & p. id )
127
+ } ;
128
+ match opt_def {
129
+ Some ( DefStatic ( did, false ) ) => {
126
130
let const_expr = lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
127
131
match eval_const_expr ( cx. tcx , const_expr) {
128
132
const_float( f) if f. is_nan ( ) => true ,
@@ -334,9 +338,13 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
334
338
match pat. node {
335
339
PatWild | PatWildMulti => { None }
336
340
PatIdent ( _, _, _) | PatEnum ( _, _) => {
337
- match cx. tcx . def_map . find ( & pat. id ) {
338
- Some ( & DefVariant ( _, id, _) ) => Some ( variant ( id) ) ,
339
- Some ( & DefStatic ( did, false ) ) => {
341
+ let opt_def = {
342
+ let def_map = cx. tcx . def_map . borrow ( ) ;
343
+ def_map. get ( ) . find_copy ( & pat. id )
344
+ } ;
345
+ match opt_def {
346
+ Some ( DefVariant ( _, id, _) ) => Some ( variant ( id) ) ,
347
+ Some ( DefStatic ( did, false ) ) => {
340
348
let const_expr = lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
341
349
Some ( val ( eval_const_expr ( cx. tcx , const_expr) ) )
342
350
}
@@ -348,7 +356,8 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
348
356
Some ( range ( eval_const_expr ( cx. tcx , lo) , eval_const_expr ( cx. tcx , hi) ) )
349
357
}
350
358
PatStruct ( ..) => {
351
- match cx. tcx . def_map . find ( & pat. id ) {
359
+ let def_map = cx. tcx . def_map . borrow ( ) ;
360
+ match def_map. get ( ) . find ( & pat. id ) {
352
361
Some ( & DefVariant ( _, id, _) ) => Some ( variant ( id) ) ,
353
362
_ => Some ( single)
354
363
}
@@ -370,7 +379,8 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
370
379
match pat. node {
371
380
PatWild | PatWildMulti => { true }
372
381
PatIdent ( _, _, _) => {
373
- match cx. tcx . def_map . find ( & pat. id ) {
382
+ let def_map = cx. tcx . def_map . borrow ( ) ;
383
+ match def_map. get ( ) . find ( & pat. id ) {
374
384
Some ( & DefVariant ( _, _, _) ) | Some ( & DefStatic ( ..) ) => { false }
375
385
_ => { true }
376
386
}
@@ -551,15 +561,19 @@ fn specialize(cx: &MatchCheckCtxt,
551
561
Some ( vec:: append ( vec:: from_elem ( arity, wild_multi ( ) ) , r. tail ( ) ) )
552
562
}
553
563
PatIdent ( _, _, _) => {
554
- match cx. tcx . def_map . find ( & pat_id) {
555
- Some ( & DefVariant ( _, id, _) ) => {
564
+ let opt_def = {
565
+ let def_map = cx. tcx . def_map . borrow ( ) ;
566
+ def_map. get ( ) . find_copy ( & pat_id)
567
+ } ;
568
+ match opt_def {
569
+ Some ( DefVariant ( _, id, _) ) => {
556
570
if variant ( id) == * ctor_id {
557
571
Some ( r. tail ( ) . to_owned ( ) )
558
572
} else {
559
573
None
560
574
}
561
575
}
562
- Some ( & DefStatic ( did, _) ) => {
576
+ Some ( DefStatic ( did, _) ) => {
563
577
let const_expr =
564
578
lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
565
579
let e_v = eval_const_expr ( cx. tcx , const_expr) ;
@@ -608,7 +622,11 @@ fn specialize(cx: &MatchCheckCtxt,
608
622
}
609
623
}
610
624
PatEnum ( _, args) => {
611
- match cx. tcx . def_map . get_copy ( & pat_id) {
625
+ let opt_def = {
626
+ let def_map = cx. tcx . def_map . borrow ( ) ;
627
+ def_map. get ( ) . get_copy ( & pat_id)
628
+ } ;
629
+ match opt_def {
612
630
DefStatic ( did, _) => {
613
631
let const_expr =
614
632
lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
@@ -668,7 +686,11 @@ fn specialize(cx: &MatchCheckCtxt,
668
686
}
669
687
PatStruct ( _, ref pattern_fields, _) => {
670
688
// Is this a struct or an enum variant?
671
- match cx. tcx . def_map . get_copy ( & pat_id) {
689
+ let opt_def = {
690
+ let def_map = cx. tcx . def_map . borrow ( ) ;
691
+ def_map. get ( ) . get_copy ( & pat_id)
692
+ } ;
693
+ match opt_def {
672
694
DefVariant ( _, variant_id, _) => {
673
695
if variant ( variant_id) == * ctor_id {
674
696
let struct_fields = ty:: lookup_struct_fields ( cx. tcx , variant_id) ;
@@ -838,13 +860,17 @@ fn check_fn(v: &mut CheckMatchVisitor,
838
860
}
839
861
840
862
fn is_refutable ( cx : & MatchCheckCtxt , pat : & Pat ) -> bool {
841
- match cx. tcx . def_map . find ( & pat. id ) {
842
- Some ( & DefVariant ( enum_id, _, _) ) => {
863
+ let opt_def = {
864
+ let def_map = cx. tcx . def_map . borrow ( ) ;
865
+ def_map. get ( ) . find_copy ( & pat. id )
866
+ } ;
867
+ match opt_def {
868
+ Some ( DefVariant ( enum_id, _, _) ) => {
843
869
if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
844
870
return true ;
845
871
}
846
872
}
847
- Some ( & DefStatic ( ..) ) => return true ,
873
+ Some ( DefStatic ( ..) ) => return true ,
848
874
_ => ( )
849
875
}
850
876
0 commit comments