@@ -271,11 +271,9 @@ fn const_not_var(err: &mut DiagnosticBuilder<'_>, tcx: TyCtxt<'_>, pat: &Pat, pa
271271fn check_for_bindings_named_same_as_variants ( cx : & MatchVisitor < ' _ , ' _ > , pat : & Pat ) {
272272 pat. walk ( |p| {
273273 if let hir:: PatKind :: Binding ( _, _, ident, None ) = p. kind {
274- if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
275- if bm != ty:: BindByValue ( hir:: Mutability :: Not ) {
276- // Nothing to check.
277- return true ;
278- }
274+ if let Some ( ty:: BindByValue ( hir:: Mutability :: Not ) ) =
275+ cx. tables . extract_binding_mode ( cx. tcx . sess , p. hir_id , p. span )
276+ {
279277 let pat_ty = cx. tables . pat_ty ( p) ;
280278 if let ty:: Adt ( edef, _) = pat_ty. kind {
281279 if edef. is_enum ( )
@@ -303,8 +301,6 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
303301 err. emit ( ) ;
304302 }
305303 }
306- } else {
307- cx. tcx . sess . delay_span_bug ( p. span , "missing binding mode" ) ;
308304 }
309305 }
310306 true
@@ -581,15 +577,14 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span>
581577
582578// Check the legality of legality of by-move bindings.
583579fn check_legality_of_move_bindings ( cx : & mut MatchVisitor < ' _ , ' _ > , has_guard : bool , pat : & Pat ) {
580+ let sess = cx. tcx . sess ;
581+ let tables = cx. tables ;
582+
584583 // Find all by-ref spans.
585584 let mut by_ref_spans = Vec :: new ( ) ;
586585 pat. each_binding ( |_, hir_id, span, _| {
587- if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( hir_id) {
588- if let ty:: BindByReference ( ..) = bm {
589- by_ref_spans. push ( span) ;
590- }
591- } else {
592- cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
586+ if let Some ( ty:: BindByReference ( _) ) = tables. extract_binding_mode ( sess, hir_id, span) {
587+ by_ref_spans. push ( span) ;
593588 }
594589 } ) ;
595590
@@ -600,7 +595,7 @@ fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: boo
600595 //
601596 // `x @ Foo(..)` is legal, but `x @ Foo(y)` isn't.
602597 if sub. map_or ( false , |p| p. contains_bindings ( ) ) {
603- struct_span_err ! ( cx . tcx . sess, p. span, E0007 , "cannot bind by-move with sub-bindings" )
598+ struct_span_err ! ( sess, p. span, E0007 , "cannot bind by-move with sub-bindings" )
604599 . span_label ( p. span , "binds an already bound by-move value by moving it" )
605600 . emit ( ) ;
606601 } else if !has_guard && !by_ref_spans. is_empty ( ) {
@@ -609,15 +604,11 @@ fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: boo
609604 } ;
610605 pat. walk ( |p| {
611606 if let hir:: PatKind :: Binding ( .., sub) = & p. kind {
612- if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
613- if let ty:: BindByValue ( ..) = bm {
614- let pat_ty = cx. tables . node_type ( p. hir_id ) ;
615- if !pat_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env , pat. span ) {
616- check_move ( p, sub. as_deref ( ) ) ;
617- }
607+ if let Some ( ty:: BindByValue ( _) ) = tables. extract_binding_mode ( sess, p. hir_id , p. span ) {
608+ let pat_ty = tables. node_type ( p. hir_id ) ;
609+ if !pat_ty. is_copy_modulo_regions ( cx. tcx , cx. param_env , pat. span ) {
610+ check_move ( p, sub. as_deref ( ) ) ;
618611 }
619- } else {
620- cx. tcx . sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
621612 }
622613 }
623614 true
@@ -626,7 +617,7 @@ fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: boo
626617 // Found some bad by-move spans, error!
627618 if !by_move_spans. is_empty ( ) {
628619 let mut err = struct_span_err ! (
629- cx . tcx . sess,
620+ sess,
630621 MultiSpan :: from_spans( by_move_spans. clone( ) ) ,
631622 E0009 ,
632623 "cannot bind by-move and by-ref in the same pattern" ,
@@ -642,14 +633,12 @@ fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: boo
642633}
643634
644635fn check_borrow_conflicts_in_at_patterns ( cx : & MatchVisitor < ' _ , ' _ > , pat : & Pat ) {
636+ let tab = cx. tables ;
637+ let sess = cx. tcx . sess ;
645638 // Get the mutability of `p` if it's by-ref.
646- let extract_binding_mut = |hir_id, span| match cx. tables . pat_binding_modes ( ) . get ( hir_id) {
647- None => {
648- cx. tcx . sess . delay_span_bug ( span, "missing binding mode" ) ;
649- None
650- }
651- Some ( ty:: BindByValue ( ..) ) => None ,
652- Some ( ty:: BindByReference ( m) ) => Some ( * m) ,
639+ let extract_binding_mut = |hir_id, span| match tab. extract_binding_mode ( sess, hir_id, span) ? {
640+ ty:: BindByValue ( _) => None ,
641+ ty:: BindByReference ( m) => Some ( m) ,
653642 } ;
654643 pat. walk ( |pat| {
655644 // Extract `sub` in `binding @ sub`.
@@ -671,8 +660,8 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
671660 sub. each_binding ( |_, hir_id, span, _| {
672661 if let Some ( mut_inner) = extract_binding_mut ( hir_id, span) {
673662 match ( mut_outer, mut_inner) {
674- ( Mutability :: Immutable , Mutability :: Immutable ) => { }
675- ( Mutability :: Mutable , Mutability :: Mutable ) => conflicts_mut_mut. push ( span) ,
663+ ( Mutability :: Not , Mutability :: Not ) => { }
664+ ( Mutability :: Mut , Mutability :: Mut ) => conflicts_mut_mut. push ( span) ,
676665 _ => conflicts_mut_ref. push ( span) ,
677666 }
678667 }
@@ -683,7 +672,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
683672 if !conflicts_mut_mut. is_empty ( ) {
684673 // Report mutability conflicts for e.g. `ref mut x @ Some(ref mut y)`.
685674 let msg = & format ! ( "cannot borrow `{}` as mutable more than once at a time" , name) ;
686- let mut err = cx . tcx . sess . struct_span_err ( pat. span , msg) ;
675+ let mut err = sess. struct_span_err ( pat. span , msg) ;
687676 err. span_label ( binding_span, "first mutable borrow occurs here" ) ;
688677 for sp in conflicts_mut_mut {
689678 err. span_label ( sp, "another mutable borrow occurs here" ) ;
@@ -695,14 +684,14 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
695684 } else if !conflicts_mut_ref. is_empty ( ) {
696685 // Report mutability conflicts for e.g. `ref x @ Some(ref mut y)` or the converse.
697686 let ( primary, also) = match mut_outer {
698- Mutability :: Mutable => ( "mutable" , "immutable" ) ,
699- Mutability :: Immutable => ( "immutable" , "mutable" ) ,
687+ Mutability :: Mut => ( "mutable" , "immutable" ) ,
688+ Mutability :: Not => ( "immutable" , "mutable" ) ,
700689 } ;
701690 let msg = & format ! (
702691 "cannot borrow `{}` as {} because it is also borrowed as {}" ,
703692 name, primary, also,
704693 ) ;
705- let mut err = cx . tcx . sess . struct_span_err ( pat. span , msg) ;
694+ let mut err = sess. struct_span_err ( pat. span , msg) ;
706695 err. span_label ( binding_span, & format ! ( "{} borrow occurs here" , primary) ) ;
707696 for sp in conflicts_mut_ref {
708697 err. span_label ( sp, & format ! ( "{} borrow occurs here" , also) ) ;
0 commit comments