@@ -121,8 +121,12 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
121121
122122 // Check that we do not match against a static NaN (#6804)
123123 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 ) ) => {
126130 let const_expr = lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
127131 match eval_const_expr ( cx. tcx , const_expr) {
128132 const_float( f) if f. is_nan ( ) => true ,
@@ -334,9 +338,13 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
334338 match pat. node {
335339 PatWild | PatWildMulti => { None }
336340 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 ) ) => {
340348 let const_expr = lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
341349 Some ( val ( eval_const_expr ( cx. tcx , const_expr) ) )
342350 }
@@ -348,7 +356,8 @@ fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
348356 Some ( range ( eval_const_expr ( cx. tcx , lo) , eval_const_expr ( cx. tcx , hi) ) )
349357 }
350358 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 ) {
352361 Some ( & DefVariant ( _, id, _) ) => Some ( variant ( id) ) ,
353362 _ => Some ( single)
354363 }
@@ -370,7 +379,8 @@ fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
370379 match pat. node {
371380 PatWild | PatWildMulti => { true }
372381 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 ) {
374384 Some ( & DefVariant ( _, _, _) ) | Some ( & DefStatic ( ..) ) => { false }
375385 _ => { true }
376386 }
@@ -551,15 +561,19 @@ fn specialize(cx: &MatchCheckCtxt,
551561 Some ( vec:: append ( vec:: from_elem ( arity, wild_multi ( ) ) , r. tail ( ) ) )
552562 }
553563 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, _) ) => {
556570 if variant ( id) == * ctor_id {
557571 Some ( r. tail ( ) . to_owned ( ) )
558572 } else {
559573 None
560574 }
561575 }
562- Some ( & DefStatic ( did, _) ) => {
576+ Some ( DefStatic ( did, _) ) => {
563577 let const_expr =
564578 lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
565579 let e_v = eval_const_expr ( cx. tcx , const_expr) ;
@@ -608,7 +622,11 @@ fn specialize(cx: &MatchCheckCtxt,
608622 }
609623 }
610624 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 {
612630 DefStatic ( did, _) => {
613631 let const_expr =
614632 lookup_const_by_id ( cx. tcx , did) . unwrap ( ) ;
@@ -668,7 +686,11 @@ fn specialize(cx: &MatchCheckCtxt,
668686 }
669687 PatStruct ( _, ref pattern_fields, _) => {
670688 // 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 {
672694 DefVariant ( _, variant_id, _) => {
673695 if variant ( variant_id) == * ctor_id {
674696 let struct_fields = ty:: lookup_struct_fields ( cx. tcx , variant_id) ;
@@ -838,13 +860,17 @@ fn check_fn(v: &mut CheckMatchVisitor,
838860}
839861
840862fn 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, _, _) ) => {
843869 if ty:: enum_variants ( cx. tcx , enum_id) . len ( ) != 1 u {
844870 return true ;
845871 }
846872 }
847- Some ( & DefStatic ( ..) ) => return true ,
873+ Some ( DefStatic ( ..) ) => return true ,
848874 _ => ( )
849875 }
850876
0 commit comments