@@ -723,6 +723,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
723723 ) ;
724724 }
725725
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+
726739 pub ( crate ) fn check_lhs_assignable (
727740 & self ,
728741 lhs : & ' tcx hir:: Expr ,
@@ -736,17 +749,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
736749 DiagnosticId :: Error ( err_code. into ( ) ) ,
737750 ) ;
738751 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) {
750753 err. note ( "destructuring assignments are not yet supported" ) ;
751754 err. note (
752755 "for more information, see https://github.com/rust-lang/rfcs/issues/372" ,
0 commit comments