File tree 3 files changed +56
-0
lines changed
3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -2314,6 +2314,7 @@ impl<'a> Parser<'a> {
2314
2314
2315
2315
while self . token != token:: CloseDelim ( token:: Brace ) {
2316
2316
if self . eat ( & token:: DotDot ) {
2317
+ let exp_span = self . prev_span ;
2317
2318
match self . parse_expr ( ) {
2318
2319
Ok ( e) => {
2319
2320
base = Some ( e) ;
@@ -2323,6 +2324,16 @@ impl<'a> Parser<'a> {
2323
2324
self . recover_stmt ( ) ;
2324
2325
}
2325
2326
}
2327
+ if self . token == token:: Comma {
2328
+ let mut err = self . sess . span_diagnostic . mut_span_err (
2329
+ exp_span. to ( self . prev_span ) ,
2330
+ "cannot use a comma after the base struct" ,
2331
+ ) ;
2332
+ err. span_suggestion_short ( self . span , "remove this comma" , "" . to_owned ( ) ) ;
2333
+ err. note ( "the base struct must always be the last field" ) ;
2334
+ err. emit ( ) ;
2335
+ self . recover_stmt ( ) ;
2336
+ }
2326
2337
break ;
2327
2338
}
2328
2339
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // compile-flags: -Z parse-only
12
+
13
+ // issue #41834
14
+
15
+ fn main ( ) {
16
+ let foo = Foo {
17
+ one : 111 ,
18
+ ..Foo :: default ( ) ,
19
+ //~^ ERROR cannot use a comma after struct expansion
20
+ } ;
21
+
22
+ let foo = Foo {
23
+ ..Foo :: default ( ) ,
24
+ //~^ ERROR cannot use a comma after struct expansion
25
+ one : 111 ,
26
+ } ;
27
+ }
Original file line number Diff line number Diff line change
1
+ error: cannot use a comma after the base struct
2
+ --> $DIR/struct-field-init-syntax.rs:18:9
3
+ |
4
+ 18 | ..Foo::default(),
5
+ | ^^^^^^^^^^^^^^^^- help: remove this comma
6
+ |
7
+ = note: the base struct must always be the last field
8
+
9
+ error: cannot use a comma after the base struct
10
+ --> $DIR/struct-field-init-syntax.rs:23:9
11
+ |
12
+ 23 | ..Foo::default(),
13
+ | ^^^^^^^^^^^^^^^^- help: remove this comma
14
+ |
15
+ = note: the base struct must always be the last field
16
+
17
+ error: aborting due to 2 previous errors
18
+
You can’t perform that action at this time.
0 commit comments