@@ -1305,7 +1305,8 @@ impl<'a> Parser<'a> {
1305
1305
1306
1306
let ( variants, _) = self
1307
1307
. parse_delim_comma_seq ( Delimiter :: Brace , |p| p. parse_enum_variant ( ) )
1308
- . map_err ( |e| {
1308
+ . map_err ( |mut e| {
1309
+ e. span_label ( id. span , "while parsing this enum" ) ;
1309
1310
self . recover_stmt ( ) ;
1310
1311
e
1311
1312
} ) ?;
@@ -1330,7 +1331,8 @@ impl<'a> Parser<'a> {
1330
1331
1331
1332
let struct_def = if this. check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
1332
1333
// Parse a struct variant.
1333
- let ( fields, recovered) = this. parse_record_struct_body ( "struct" , false ) ?;
1334
+ let ( fields, recovered) =
1335
+ this. parse_record_struct_body ( "struct" , ident. span , false ) ?;
1334
1336
VariantData :: Struct ( fields, recovered)
1335
1337
} else if this. check ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) {
1336
1338
VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1384,17 +1386,23 @@ impl<'a> Parser<'a> {
1384
1386
VariantData :: Unit ( DUMMY_NODE_ID )
1385
1387
} else {
1386
1388
// If we see: `struct Foo<T> where T: Copy { ... }`
1387
- let ( fields, recovered) =
1388
- self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
1389
+ let ( fields, recovered) = self . parse_record_struct_body (
1390
+ "struct" ,
1391
+ class_name. span ,
1392
+ generics. where_clause . has_where_token ,
1393
+ ) ?;
1389
1394
VariantData :: Struct ( fields, recovered)
1390
1395
}
1391
1396
// No `where` so: `struct Foo<T>;`
1392
1397
} else if self . eat ( & token:: Semi ) {
1393
1398
VariantData :: Unit ( DUMMY_NODE_ID )
1394
1399
// Record-style struct definition
1395
1400
} else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1396
- let ( fields, recovered) =
1397
- self . parse_record_struct_body ( "struct" , generics. where_clause . has_where_token ) ?;
1401
+ let ( fields, recovered) = self . parse_record_struct_body (
1402
+ "struct" ,
1403
+ class_name. span ,
1404
+ generics. where_clause . has_where_token ,
1405
+ ) ?;
1398
1406
VariantData :: Struct ( fields, recovered)
1399
1407
// Tuple-style struct definition with optional where-clause.
1400
1408
} else if self . token == token:: OpenDelim ( Delimiter :: Parenthesis ) {
@@ -1423,12 +1431,18 @@ impl<'a> Parser<'a> {
1423
1431
1424
1432
let vdata = if self . token . is_keyword ( kw:: Where ) {
1425
1433
generics. where_clause = self . parse_where_clause ( ) ?;
1426
- let ( fields, recovered) =
1427
- self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
1434
+ let ( fields, recovered) = self . parse_record_struct_body (
1435
+ "union" ,
1436
+ class_name. span ,
1437
+ generics. where_clause . has_where_token ,
1438
+ ) ?;
1428
1439
VariantData :: Struct ( fields, recovered)
1429
1440
} else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1430
- let ( fields, recovered) =
1431
- self . parse_record_struct_body ( "union" , generics. where_clause . has_where_token ) ?;
1441
+ let ( fields, recovered) = self . parse_record_struct_body (
1442
+ "union" ,
1443
+ class_name. span ,
1444
+ generics. where_clause . has_where_token ,
1445
+ ) ?;
1432
1446
VariantData :: Struct ( fields, recovered)
1433
1447
} else {
1434
1448
let token_str = super :: token_descr ( & self . token ) ;
@@ -1444,6 +1458,7 @@ impl<'a> Parser<'a> {
1444
1458
fn parse_record_struct_body (
1445
1459
& mut self ,
1446
1460
adt_ty : & str ,
1461
+ ident_span : Span ,
1447
1462
parsed_where : bool ,
1448
1463
) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
1449
1464
let mut fields = Vec :: new ( ) ;
@@ -1458,6 +1473,7 @@ impl<'a> Parser<'a> {
1458
1473
match field {
1459
1474
Ok ( field) => fields. push ( field) ,
1460
1475
Err ( mut err) => {
1476
+ err. span_label ( ident_span, format ! ( "while parsing this {adt_ty}" ) ) ;
1461
1477
err. emit ( ) ;
1462
1478
break ;
1463
1479
}
0 commit comments