@@ -1781,7 +1781,7 @@ impl<'a> Parser<'a> {
17811781 let mut recovered = Recovered :: No ;
17821782 if self . eat ( exp ! ( OpenBrace ) ) {
17831783 while self . token != token:: CloseBrace {
1784- match self . parse_field_def ( adt_ty) {
1784+ match self . parse_field_def ( adt_ty, ident_span ) {
17851785 Ok ( field) => {
17861786 fields. push ( field) ;
17871787 }
@@ -1894,15 +1894,15 @@ impl<'a> Parser<'a> {
18941894 }
18951895
18961896 /// Parses an element of a struct declaration.
1897- fn parse_field_def ( & mut self , adt_ty : & str ) -> PResult < ' a , FieldDef > {
1897+ fn parse_field_def ( & mut self , adt_ty : & str , ident_span : Span ) -> PResult < ' a , FieldDef > {
18981898 self . recover_vcs_conflict_marker ( ) ;
18991899 let attrs = self . parse_outer_attributes ( ) ?;
19001900 self . recover_vcs_conflict_marker ( ) ;
19011901 self . collect_tokens ( None , attrs, ForceCollect :: No , |this, attrs| {
19021902 let lo = this. token . span ;
19031903 let vis = this. parse_visibility ( FollowedByType :: No ) ?;
19041904 let safety = this. parse_unsafe_field ( ) ;
1905- this. parse_single_struct_field ( adt_ty, lo, vis, safety, attrs)
1905+ this. parse_single_struct_field ( adt_ty, lo, vis, safety, attrs, ident_span )
19061906 . map ( |field| ( field, Trailing :: No , UsePreAttrPos :: No ) )
19071907 } )
19081908 }
@@ -1915,24 +1915,27 @@ impl<'a> Parser<'a> {
19151915 vis : Visibility ,
19161916 safety : Safety ,
19171917 attrs : AttrVec ,
1918+ ident_span : Span ,
19181919 ) -> PResult < ' a , FieldDef > {
19191920 let a_var = self . parse_name_and_ty ( adt_ty, lo, vis, safety, attrs) ?;
1920- if self . eat ( exp ! ( Semi ) ) {
1921- let sp = self . prev_token . span ;
1922- let mut err =
1923- self . dcx ( ) . struct_span_err ( sp, format ! ( "{adt_ty} fields are separated by `,`" ) ) ;
1924- err. span_suggestion_short (
1925- sp,
1926- "replace `;` with `,`" ,
1927- "," ,
1928- Applicability :: MachineApplicable ,
1929- ) ;
1930- return Err ( err) ;
1931- }
19321921 match self . token . kind {
19331922 token:: Comma => {
19341923 self . bump ( ) ;
19351924 }
1925+ token:: Semi => {
1926+ self . bump ( ) ;
1927+ let sp = self . prev_token . span ;
1928+ let mut err =
1929+ self . dcx ( ) . struct_span_err ( sp, format ! ( "{adt_ty} fields are separated by `,`" ) ) ;
1930+ err. span_suggestion_short (
1931+ sp,
1932+ "replace `;` with `,`" ,
1933+ "," ,
1934+ Applicability :: MachineApplicable ,
1935+ ) ;
1936+ err. span_label ( ident_span, format ! ( "while parsing this {adt_ty}" ) ) ;
1937+ err. emit ( ) ;
1938+ }
19361939 token:: CloseBrace => { }
19371940 token:: DocComment ( ..) => {
19381941 let previous_span = self . prev_token . span ;
0 commit comments