@@ -861,7 +861,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
861861 }
862862
863863 /// Destructure the LHS of complex assignments.
864- /// For instance, lower `(a,b) = t` to `{ let (lhs1,lhs2) = t; a = lhs1; b = lhs2; }`.
864+ /// For instance, lower `(a, b) = t` to `{ let (lhs1, lhs2) = t; a = lhs1; b = lhs2; }`.
865865 fn lower_expr_assign (
866866 & mut self ,
867867 lhs : & Expr ,
@@ -902,13 +902,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
902902 return hir:: ExprKind :: Assign ( self . lower_expr ( lhs) , self . lower_expr ( rhs) , eq_sign_span) ;
903903 }
904904
905- let mut assignments = Vec :: new ( ) ;
905+ let mut assignments = vec ! [ ] ;
906906
907- // The LHS becomes a pattern: `(lhs1, lhs2)`
907+ // The LHS becomes a pattern: `(lhs1, lhs2)`.
908908 let pat = self . destructure_assign ( lhs, eq_sign_span, & mut assignments) ;
909909 let rhs = self . lower_expr ( rhs) ;
910910
911- // Introduce a let for destructuring: `let (lhs1,lhs2) = t`.
911+ // Introduce a ` let` for destructuring: `let (lhs1, lhs2) = t`.
912912 let destructure_let = self . stmt_let_pat (
913913 ThinVec :: new ( ) ,
914914 whole_span,
@@ -927,18 +927,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
927927 }
928928
929929 /// Convert the LHS of a destructuring assignment to a pattern.
930- /// Along the way, introduce additional assignments in the parameter assignments.
930+ /// Each sub-assignment is recorded in ` assignments` .
931931 fn destructure_assign (
932932 & mut self ,
933933 lhs : & Expr ,
934934 eq_sign_span : Span ,
935935 assignments : & mut Vec < hir:: Stmt < ' hir > > ,
936936 ) -> & ' hir hir:: Pat < ' hir > {
937937 match & lhs. kind {
938+ // Underscore pattern.
938939 ExprKind :: Underscore => {
939940 return self . pat ( lhs. span , hir:: PatKind :: Wild ) ;
940941 }
941- // slices:
942+ // Slice patterns.
942943 ExprKind :: Array ( elements) => {
943944 let ( pats, rest) =
944945 self . destructure_sequence ( elements, "slice" , eq_sign_span, assignments) ;
@@ -950,7 +951,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
950951 } ;
951952 return self . pat ( lhs. span , slice_pat) ;
952953 }
953- // tuple structs:
954+ // Tuple structs.
954955 ExprKind :: Call ( callee, args) => {
955956 if let ExprKind :: Path ( qself, path) = & callee. kind {
956957 let ( pats, rest) =
@@ -979,7 +980,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
979980 }
980981 }
981982 }
982- // structs:
983+ // Structs.
983984 ExprKind :: Struct ( path, fields, base) => {
984985 let field_pats = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| {
985986 let pat = self . destructure_assign ( & f. expr , eq_sign_span, assignments) ;
@@ -1005,10 +1006,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
10051006 ExprKind :: Underscore => { }
10061007 _ => self
10071008 . sess
1008- . struct_span_err ( e. span , "base expression not allowed here" )
1009+ . struct_span_err (
1010+ e. span ,
1011+ "functional record updates are not allowed in destructuring \
1012+ assignments",
1013+ )
10091014 . span_suggestion (
10101015 e. span ,
1011- "consider removing this " ,
1016+ "consider removing the trailing pattern " ,
10121017 String :: new ( ) ,
10131018 rustc_errors:: Applicability :: MachineApplicable ,
10141019 )
@@ -1020,7 +1025,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10201025 let struct_pat = hir:: PatKind :: Struct ( qpath, field_pats, fields_omitted) ;
10211026 return self . pat ( lhs. span , struct_pat) ;
10221027 }
1023- // tuples:
1028+ // Tuples.
10241029 ExprKind :: Tup ( elements) => {
10251030 let ( pats, rest) =
10261031 self . destructure_sequence ( elements, "tuple" , eq_sign_span, assignments) ;
@@ -1041,8 +1046,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
10411046
10421047 /// Destructure a sequence of expressions occurring on the LHS of an assignment.
10431048 /// Such a sequence occurs in a tuple (struct)/slice.
1044- /// Return a sequence of corresponding patterns and the index and span of `..`, if any.
1045- /// Along the way, introduce additional assignments in the parameter `assignments`.
1049+ /// Return a sequence of corresponding patterns, and the index and the span of `..` if it
1050+ /// exists.
1051+ /// Each sub-assignment is recorded in `assignments`.
10461052 fn destructure_sequence (
10471053 & mut self ,
10481054 elements : & [ AstP < Expr > ] ,
0 commit comments