@@ -1318,7 +1318,8 @@ impl<'a> Parser<'a> {
1318
1318
( vec ! [ ] , false )
1319
1319
} else {
1320
1320
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" ) ;
1322
1323
self . recover_stmt ( ) ;
1323
1324
e
1324
1325
} ,
@@ -1345,7 +1346,8 @@ impl<'a> Parser<'a> {
1345
1346
1346
1347
let struct_def = if this. check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
1347
1348
// 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 ) ?;
1349
1351
VariantData :: Struct ( fields, recovered)
1350
1352
} else if this. check ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) {
1351
1353
VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1399,17 +1401,23 @@ impl<'a> Parser<'a> {
1399
1401
VariantData :: Unit ( DUMMY_NODE_ID )
1400
1402
} else {
1401
1403
// 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
+ ) ?;
1404
1409
VariantData :: Struct ( fields, recovered)
1405
1410
}
1406
1411
// No `where` so: `struct Foo<T>;`
1407
1412
} else if self . eat ( & token:: Semi ) {
1408
1413
VariantData :: Unit ( DUMMY_NODE_ID )
1409
1414
// Record-style struct definition
1410
1415
} 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
+ ) ?;
1413
1421
VariantData :: Struct ( fields, recovered)
1414
1422
// Tuple-style struct definition with optional where-clause.
1415
1423
} else if self . token == token:: OpenDelim ( Delimiter :: Parenthesis ) {
@@ -1438,12 +1446,18 @@ impl<'a> Parser<'a> {
1438
1446
1439
1447
let vdata = if self . token . is_keyword ( kw:: Where ) {
1440
1448
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
+ ) ?;
1443
1454
VariantData :: Struct ( fields, recovered)
1444
1455
} 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
+ ) ?;
1447
1461
VariantData :: Struct ( fields, recovered)
1448
1462
} else {
1449
1463
let token_str = super :: token_descr ( & self . token ) ;
@@ -1459,6 +1473,7 @@ impl<'a> Parser<'a> {
1459
1473
fn parse_record_struct_body (
1460
1474
& mut self ,
1461
1475
adt_ty : & str ,
1476
+ ident_span : Span ,
1462
1477
parsed_where : bool ,
1463
1478
) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
1464
1479
let mut fields = Vec :: new ( ) ;
@@ -1473,6 +1488,7 @@ impl<'a> Parser<'a> {
1473
1488
match field {
1474
1489
Ok ( field) => fields. push ( field) ,
1475
1490
Err ( mut err) => {
1491
+ err. span_label ( ident_span, format ! ( "while parsing this {adt_ty}" ) ) ;
1476
1492
err. emit ( ) ;
1477
1493
break ;
1478
1494
}
0 commit comments