@@ -840,6 +840,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
840
840
fn walk_pat ( & mut self , cmt_discr : mc:: cmt < ' tcx > , pat : & hir:: Pat , match_mode : MatchMode ) {
841
841
debug ! ( "walk_pat(cmt_discr={:?}, pat={:?})" , cmt_discr, pat) ;
842
842
843
+ let tcx = self . tcx ( ) ;
843
844
let ExprUseVisitor { ref mc, ref mut delegate, param_env } = * self ;
844
845
return_if_err ! ( mc. cat_pattern( cmt_discr. clone( ) , pat, |cmt_pat, pat| {
845
846
if let PatKind :: Binding ( _, canonical_id, ..) = pat. node {
@@ -849,34 +850,36 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
849
850
pat,
850
851
match_mode,
851
852
) ;
852
- let bm = * mc. tables. pat_binding_modes( ) . get( pat. hir_id)
853
- . expect( "missing binding mode" ) ;
854
- debug!( "walk_pat: pat.hir_id={:?} bm={:?}" , pat. hir_id, bm) ;
855
-
856
- // pat_ty: the type of the binding being produced.
857
- let pat_ty = return_if_err!( mc. node_ty( pat. hir_id) ) ;
858
- debug!( "walk_pat: pat_ty={:?}" , pat_ty) ;
859
-
860
- // Each match binding is effectively an assignment to the
861
- // binding being produced.
862
- let def = Def :: Local ( canonical_id) ;
863
- if let Ok ( ref binding_cmt) = mc. cat_def( pat. hir_id, pat. span, pat_ty, def) {
864
- delegate. mutate( pat. id, pat. span, binding_cmt, MutateMode :: Init ) ;
865
- }
853
+ if let Some ( & bm) = mc. tables. pat_binding_modes( ) . get( pat. hir_id) {
854
+ debug!( "walk_pat: pat.hir_id={:?} bm={:?}" , pat. hir_id, bm) ;
855
+
856
+ // pat_ty: the type of the binding being produced.
857
+ let pat_ty = return_if_err!( mc. node_ty( pat. hir_id) ) ;
858
+ debug!( "walk_pat: pat_ty={:?}" , pat_ty) ;
859
+
860
+ // Each match binding is effectively an assignment to the
861
+ // binding being produced.
862
+ let def = Def :: Local ( canonical_id) ;
863
+ if let Ok ( ref binding_cmt) = mc. cat_def( pat. hir_id, pat. span, pat_ty, def) {
864
+ delegate. mutate( pat. id, pat. span, binding_cmt, MutateMode :: Init ) ;
865
+ }
866
866
867
- // It is also a borrow or copy/move of the value being matched.
868
- match bm {
869
- ty:: BindByReference ( m) => {
870
- if let ty:: TyRef ( r, _, _) = pat_ty. sty {
871
- let bk = ty:: BorrowKind :: from_mutbl( m) ;
872
- delegate. borrow( pat. id, pat. span, & cmt_pat, r, bk, RefBinding ) ;
867
+ // It is also a borrow or copy/move of the value being matched.
868
+ match bm {
869
+ ty:: BindByReference ( m) => {
870
+ if let ty:: TyRef ( r, _, _) = pat_ty. sty {
871
+ let bk = ty:: BorrowKind :: from_mutbl( m) ;
872
+ delegate. borrow( pat. id, pat. span, & cmt_pat, r, bk, RefBinding ) ;
873
+ }
874
+ }
875
+ ty:: BindByValue ( ..) => {
876
+ let mode = copy_or_move( mc, param_env, & cmt_pat, PatBindingMove ) ;
877
+ debug!( "walk_pat binding consuming pat" ) ;
878
+ delegate. consume_pat( pat, & cmt_pat, mode) ;
873
879
}
874
880
}
875
- ty:: BindByValue ( ..) => {
876
- let mode = copy_or_move( mc, param_env, & cmt_pat, PatBindingMove ) ;
877
- debug!( "walk_pat binding consuming pat" ) ;
878
- delegate. consume_pat( pat, & cmt_pat, mode) ;
879
- }
881
+ } else {
882
+ tcx. sess. delay_span_bug( pat. span, "missing binding mode" ) ;
880
883
}
881
884
}
882
885
} ) ) ;
0 commit comments