@@ -761,6 +761,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
761761 ) ;
762762 }
763763
764+ fn is_destructuring_place_expr ( & self , expr : & ' tcx hir:: Expr ) -> bool {
765+ match & expr. kind {
766+ ExprKind :: Array ( comps) | ExprKind :: Tup ( comps) => {
767+ comps. iter ( ) . all ( |e| self . is_destructuring_place_expr ( e) )
768+ }
769+ ExprKind :: Struct ( _path, fields, rest) => {
770+ rest. as_ref ( ) . map ( |e| self . is_destructuring_place_expr ( e) ) . unwrap_or ( true ) &&
771+ fields. iter ( ) . all ( |f| self . is_destructuring_place_expr ( & f. expr ) )
772+ }
773+ _ => expr. is_syntactic_place_expr ( ) ,
774+ }
775+ }
776+
764777 pub ( crate ) fn check_lhs_assignable (
765778 & self ,
766779 lhs : & ' tcx hir:: Expr ,
@@ -774,17 +787,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774787 DiagnosticId :: Error ( err_code. into ( ) ) ,
775788 ) ;
776789 err. span_label ( lhs. span , "cannot assign to this expression" ) ;
777- let destructuring_assignment = match & lhs. kind {
778- ExprKind :: Array ( comps) | ExprKind :: Tup ( comps) => {
779- comps. iter ( ) . all ( |e| e. is_syntactic_place_expr ( ) )
780- }
781- ExprKind :: Struct ( _path, fields, rest) => {
782- rest. as_ref ( ) . map ( |e| e. is_syntactic_place_expr ( ) ) . unwrap_or ( true ) &&
783- fields. iter ( ) . all ( |f| f. expr . is_syntactic_place_expr ( ) )
784- }
785- _ => false ,
786- } ;
787- if destructuring_assignment {
790+ if self . is_destructuring_place_expr ( lhs) {
788791 err. note ( "destructuring assignments are not yet supported" ) ;
789792 err. note (
790793 "for more information, see https://github.com/rust-lang/rfcs/issues/372" ,
0 commit comments