@@ -723,6 +723,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
723
723
) ;
724
724
}
725
725
726
+ fn is_destructuring_place_expr ( & self , expr : & ' tcx hir:: Expr ) -> bool {
727
+ match & expr. kind {
728
+ ExprKind :: Array ( comps) | ExprKind :: Tup ( comps) => {
729
+ comps. iter ( ) . all ( |e| self . is_destructuring_place_expr ( e) )
730
+ }
731
+ ExprKind :: Struct ( _path, fields, rest) => {
732
+ rest. as_ref ( ) . map ( |e| self . is_destructuring_place_expr ( e) ) . unwrap_or ( true ) &&
733
+ fields. iter ( ) . all ( |f| self . is_destructuring_place_expr ( & f. expr ) )
734
+ }
735
+ _ => expr. is_syntactic_place_expr ( ) ,
736
+ }
737
+ }
738
+
726
739
pub ( crate ) fn check_lhs_assignable (
727
740
& self ,
728
741
lhs : & ' tcx hir:: Expr ,
@@ -736,17 +749,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
736
749
DiagnosticId :: Error ( err_code. into ( ) ) ,
737
750
) ;
738
751
err. span_label ( lhs. span , "cannot assign to this expression" ) ;
739
- let destructuring_assignment = match & lhs. kind {
740
- ExprKind :: Array ( comps) | ExprKind :: Tup ( comps) => {
741
- comps. iter ( ) . all ( |e| e. is_syntactic_place_expr ( ) )
742
- }
743
- ExprKind :: Struct ( _path, fields, rest) => {
744
- rest. as_ref ( ) . map ( |e| e. is_syntactic_place_expr ( ) ) . unwrap_or ( true ) &&
745
- fields. iter ( ) . all ( |f| f. expr . is_syntactic_place_expr ( ) )
746
- }
747
- _ => false ,
748
- } ;
749
- if destructuring_assignment {
752
+ if self . is_destructuring_place_expr ( lhs) {
750
753
err. note ( "destructuring assignments are not yet supported" ) ;
751
754
err. note (
752
755
"for more information, see https://github.com/rust-lang/rfcs/issues/372" ,
0 commit comments