@@ -612,8 +612,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
612
612
match local. init {
613
613
None => {
614
614
let delegate = & mut self . delegate ;
615
- pat_util:: pat_bindings ( & self . mc . infcx . tcx . def_map , & local. pat ,
616
- |_, id, span, _| {
615
+ pat_util:: pat_bindings ( & local. pat , |_, id, span, _| {
617
616
delegate. decl_without_init ( id, span) ;
618
617
} )
619
618
}
@@ -932,23 +931,16 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
932
931
debug ! ( "determine_pat_move_mode cmt_discr={:?} pat={:?}" , cmt_discr,
933
932
pat) ;
934
933
return_if_err ! ( self . mc. cat_pattern( cmt_discr, pat, |_mc, cmt_pat, pat| {
935
- let def_map = & self . tcx( ) . def_map;
936
- if pat_util:: pat_is_binding( & def_map. borrow( ) , pat) {
937
- match pat. node {
938
- PatKind :: Binding ( hir:: BindByRef ( _) , _, _) =>
939
- mode. lub( BorrowingMatch ) ,
940
- PatKind :: Binding ( hir:: BindByValue ( _) , _, _) => {
941
- match copy_or_move( self . mc. infcx, & cmt_pat, PatBindingMove ) {
942
- Copy => mode. lub( CopyingMatch ) ,
943
- Move ( _) => mode. lub( MovingMatch ) ,
944
- }
945
- }
946
- _ => {
947
- span_bug!(
948
- pat. span,
949
- "binding pattern not an identifier" ) ;
934
+ match pat. node {
935
+ PatKind :: Binding ( hir:: BindByRef ( ..) , _, _) =>
936
+ mode. lub( BorrowingMatch ) ,
937
+ PatKind :: Binding ( hir:: BindByValue ( ..) , _, _) => {
938
+ match copy_or_move( self . mc. infcx, & cmt_pat, PatBindingMove ) {
939
+ Copy => mode. lub( CopyingMatch ) ,
940
+ Move ( ..) => mode. lub( MovingMatch ) ,
950
941
}
951
942
}
943
+ _ => { }
952
944
}
953
945
} ) ) ;
954
946
}
@@ -968,83 +960,74 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
968
960
let def_map = & self . tcx ( ) . def_map ;
969
961
let delegate = & mut self . delegate ;
970
962
return_if_err ! ( mc. cat_pattern( cmt_discr. clone( ) , pat, |mc, cmt_pat, pat| {
971
- if pat_util :: pat_is_binding ( & def_map . borrow ( ) , pat) {
972
- debug! ( "binding cmt_pat={:?} pat={:?} match_mode={:?}" ,
973
- cmt_pat ,
974
- pat ,
975
- match_mode ) ;
976
-
977
- // pat_ty: the type of the binding being produced.
978
- let pat_ty = return_if_err! ( infcx . node_ty ( pat . id ) ) ;
979
-
980
- // Each match binding is effectively an assignment to the
981
- // binding being produced.
982
- let def = def_map . borrow ( ) . get ( & pat . id ) . unwrap ( ) . full_def ( ) ;
983
- match mc . cat_def ( pat. id, pat . span , pat_ty , def ) {
984
- Ok ( binding_cmt) => {
963
+ match pat. node {
964
+ PatKind :: Binding ( bmode , _ , _ ) => {
965
+ debug! ( "binding cmt_pat={:?} pat={:?} match_mode={:?}" ,
966
+ cmt_pat ,
967
+ pat ,
968
+ match_mode ) ;
969
+
970
+ // pat_ty: the type of the binding being produced.
971
+ let pat_ty = return_if_err! ( infcx . node_ty ( pat . id ) ) ;
972
+
973
+ // Each match binding is effectively an assignment to the
974
+ // binding being produced.
975
+ let def = def_map . borrow ( ) . get ( & pat. id) . unwrap ( ) . full_def ( ) ;
976
+ if let Ok ( binding_cmt) = mc . cat_def ( pat . id , pat . span , pat_ty , def ) {
985
977
delegate. mutate( pat. id, pat. span, binding_cmt, MutateMode :: Init ) ;
986
978
}
987
- Err ( _) => { }
988
- }
989
979
990
- // It is also a borrow or copy/move of the value being matched.
991
- match pat. node {
992
- PatKind :: Binding ( hir:: BindByRef ( m) , _, _) => {
993
- if let ty:: TyRef ( & r, _) = pat_ty. sty {
994
- let bk = ty:: BorrowKind :: from_mutbl( m) ;
995
- delegate. borrow( pat. id, pat. span, cmt_pat,
996
- r, bk, RefBinding ) ;
980
+ // It is also a borrow or copy/move of the value being matched.
981
+ match bmode {
982
+ hir:: BindByRef ( m) => {
983
+ if let ty:: TyRef ( & r, _) = pat_ty. sty {
984
+ let bk = ty:: BorrowKind :: from_mutbl( m) ;
985
+ delegate. borrow( pat. id, pat. span, cmt_pat,
986
+ r, bk, RefBinding ) ;
987
+ }
988
+ }
989
+ hir:: BindByValue ( ..) => {
990
+ let mode = copy_or_move( infcx, & cmt_pat, PatBindingMove ) ;
991
+ debug!( "walk_pat binding consuming pat" ) ;
992
+ delegate. consume_pat( pat, cmt_pat, mode) ;
997
993
}
998
- }
999
- PatKind :: Binding ( hir:: BindByValue ( _) , _, _) => {
1000
- let mode = copy_or_move( infcx, & cmt_pat, PatBindingMove ) ;
1001
- debug!( "walk_pat binding consuming pat" ) ;
1002
- delegate. consume_pat( pat, cmt_pat, mode) ;
1003
- }
1004
- _ => {
1005
- span_bug!(
1006
- pat. span,
1007
- "binding pattern not an identifier" ) ;
1008
994
}
1009
995
}
1010
- } else {
1011
- match pat. node {
1012
- PatKind :: Vec ( _, Some ( ref slice_pat) , _) => {
1013
- // The `slice_pat` here creates a slice into
1014
- // the original vector. This is effectively a
1015
- // borrow of the elements of the vector being
1016
- // matched.
1017
-
1018
- let ( slice_cmt, slice_mutbl, slice_r) =
1019
- return_if_err!( mc. cat_slice_pattern( cmt_pat, & slice_pat) ) ;
1020
-
1021
- // Note: We declare here that the borrow
1022
- // occurs upon entering the `[...]`
1023
- // pattern. This implies that something like
1024
- // `[a; b]` where `a` is a move is illegal,
1025
- // because the borrow is already in effect.
1026
- // In fact such a move would be safe-ish, but
1027
- // it effectively *requires* that we use the
1028
- // nulling out semantics to indicate when a
1029
- // value has been moved, which we are trying
1030
- // to move away from. Otherwise, how can we
1031
- // indicate that the first element in the
1032
- // vector has been moved? Eventually, we
1033
- // could perhaps modify this rule to permit
1034
- // `[..a, b]` where `b` is a move, because in
1035
- // that case we can adjust the length of the
1036
- // original vec accordingly, but we'd have to
1037
- // make trans do the right thing, and it would
1038
- // only work for `Box<[T]>`s. It seems simpler
1039
- // to just require that people call
1040
- // `vec.pop()` or `vec.unshift()`.
1041
- let slice_bk = ty:: BorrowKind :: from_mutbl( slice_mutbl) ;
1042
- delegate. borrow( pat. id, pat. span,
1043
- slice_cmt, slice_r,
1044
- slice_bk, RefBinding ) ;
1045
- }
1046
- _ => { }
996
+ PatKind :: Vec ( _, Some ( ref slice_pat) , _) => {
997
+ // The `slice_pat` here creates a slice into
998
+ // the original vector. This is effectively a
999
+ // borrow of the elements of the vector being
1000
+ // matched.
1001
+
1002
+ let ( slice_cmt, slice_mutbl, slice_r) =
1003
+ return_if_err!( mc. cat_slice_pattern( cmt_pat, & slice_pat) ) ;
1004
+
1005
+ // Note: We declare here that the borrow
1006
+ // occurs upon entering the `[...]`
1007
+ // pattern. This implies that something like
1008
+ // `[a; b]` where `a` is a move is illegal,
1009
+ // because the borrow is already in effect.
1010
+ // In fact such a move would be safe-ish, but
1011
+ // it effectively *requires* that we use the
1012
+ // nulling out semantics to indicate when a
1013
+ // value has been moved, which we are trying
1014
+ // to move away from. Otherwise, how can we
1015
+ // indicate that the first element in the
1016
+ // vector has been moved? Eventually, we
1017
+ // could perhaps modify this rule to permit
1018
+ // `[..a, b]` where `b` is a move, because in
1019
+ // that case we can adjust the length of the
1020
+ // original vec accordingly, but we'd have to
1021
+ // make trans do the right thing, and it would
1022
+ // only work for `Box<[T]>`s. It seems simpler
1023
+ // to just require that people call
1024
+ // `vec.pop()` or `vec.unshift()`.
1025
+ let slice_bk = ty:: BorrowKind :: from_mutbl( slice_mutbl) ;
1026
+ delegate. borrow( pat. id, pat. span,
1027
+ slice_cmt, slice_r,
1028
+ slice_bk, RefBinding ) ;
1047
1029
}
1030
+ _ => { }
1048
1031
}
1049
1032
} ) ) ;
1050
1033
0 commit comments