@@ -1318,7 +1318,8 @@ impl<'a> Parser<'a> {
13181318 ( vec ! [ ] , false )
13191319 } else {
13201320 self . parse_delim_comma_seq ( Delimiter :: Brace , |p| p. parse_enum_variant ( ) ) . map_err (
1321- |e| {
1321+ |mut e| {
1322+ e. span_label ( id. span , "while parsing this enum" ) ;
13221323 self . recover_stmt ( ) ;
13231324 e
13241325 } ,
@@ -1345,7 +1346,8 @@ impl<'a> Parser<'a> {
13451346
13461347 let struct_def = if this. check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
13471348 // Parse a struct variant.
1348- let ( fields, recovered) = this. parse_record_struct_body ( "struct" , false ) ?;
1349+ let ( fields, recovered) =
1350+ this. parse_record_struct_body ( "struct" , ident. span , false ) ?;
13491351 VariantData :: Struct ( fields, recovered)
13501352 } else if this. check ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) {
13511353 VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1399,17 +1401,23 @@ impl<'a> Parser<'a> {
13991401 VariantData :: Unit ( DUMMY_NODE_ID )
14001402 } else {
14011403 // If we see: `struct Foo<T> where T: Copy { ... }`
1402- let ( fields, recovered) =
1403- self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
1404+ let ( fields, recovered) = self . parse_record_struct_body (
1405+ "struct" ,
1406+ class_name. span ,
1407+ generics. where_clause . has_where_token ,
1408+ ) ?;
14041409 VariantData :: Struct ( fields, recovered)
14051410 }
14061411 // No `where` so: `struct Foo<T>;`
14071412 } else if self . eat ( & token:: Semi ) {
14081413 VariantData :: Unit ( DUMMY_NODE_ID )
14091414 // Record-style struct definition
14101415 } else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1411- let ( fields, recovered) =
1412- self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
1416+ let ( fields, recovered) = self . parse_record_struct_body (
1417+ "struct" ,
1418+ class_name. span ,
1419+ generics. where_clause . has_where_token ,
1420+ ) ?;
14131421 VariantData :: Struct ( fields, recovered)
14141422 // Tuple-style struct definition with optional where-clause.
14151423 } else if self . token == token:: OpenDelim ( Delimiter :: Parenthesis ) {
@@ -1438,12 +1446,18 @@ impl<'a> Parser<'a> {
14381446
14391447 let vdata = if self . token . is_keyword ( kw:: Where ) {
14401448 generics. where_clause = self . parse_where_clause ( ) ?;
1441- let ( fields, recovered) =
1442- self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
1449+ let ( fields, recovered) = self . parse_record_struct_body (
1450+ "union" ,
1451+ class_name. span ,
1452+ generics. where_clause . has_where_token ,
1453+ ) ?;
14431454 VariantData :: Struct ( fields, recovered)
14441455 } else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1445- let ( fields, recovered) =
1446- self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
1456+ let ( fields, recovered) = self . parse_record_struct_body (
1457+ "union" ,
1458+ class_name. span ,
1459+ generics. where_clause . has_where_token ,
1460+ ) ?;
14471461 VariantData :: Struct ( fields, recovered)
14481462 } else {
14491463 let token_str = super :: token_descr ( & self . token ) ;
@@ -1459,6 +1473,7 @@ impl<'a> Parser<'a> {
14591473 fn parse_record_struct_body (
14601474 & mut self ,
14611475 adt_ty : & str ,
1476+ ident_span : Span ,
14621477 parsed_where : bool ,
14631478 ) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
14641479 let mut fields = Vec :: new ( ) ;
@@ -1473,6 +1488,7 @@ impl<'a> Parser<'a> {
14731488 match field {
14741489 Ok ( field) => fields. push ( field) ,
14751490 Err ( mut err) => {
1491+ err. span_label ( ident_span, format ! ( "while parsing this {adt_ty}" ) ) ;
14761492 err. emit ( ) ;
14771493 break ;
14781494 }
0 commit comments