@@ -761,6 +761,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
761
761
) ;
762
762
}
763
763
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
+
764
777
pub ( crate ) fn check_lhs_assignable (
765
778
& self ,
766
779
lhs : & ' tcx hir:: Expr ,
@@ -774,17 +787,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774
787
DiagnosticId :: Error ( err_code. into ( ) ) ,
775
788
) ;
776
789
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) {
788
791
err. note ( "destructuring assignments are not yet supported" ) ;
789
792
err. note (
790
793
"for more information, see https://github.com/rust-lang/rfcs/issues/372" ,
0 commit comments