@@ -1291,12 +1291,10 @@ impl<'a> Parser<'a> {
1291
1291
/// Parses an enum declaration.
1292
1292
fn parse_item_enum ( & mut self ) -> PResult < ' a , ItemInfo > {
1293
1293
if self . token . is_keyword ( kw:: Struct ) {
1294
- let mut err = self . struct_span_err (
1295
- self . prev_token . span . to ( self . token . span ) ,
1296
- "`enum` and `struct` are mutually exclusive" ,
1297
- ) ;
1294
+ let span = self . prev_token . span . to ( self . token . span ) ;
1295
+ let mut err = self . struct_span_err ( span, "`enum` and `struct` are mutually exclusive" ) ;
1298
1296
err. span_suggestion (
1299
- self . prev_token . span . to ( self . token . span ) ,
1297
+ span,
1300
1298
"replace `enum struct` with" ,
1301
1299
"enum" ,
1302
1300
Applicability :: MachineApplicable ,
@@ -1320,7 +1318,8 @@ impl<'a> Parser<'a> {
1320
1318
( vec ! [ ] , false )
1321
1319
} else {
1322
1320
self . parse_delim_comma_seq ( Delimiter :: Brace , |p| p. parse_enum_variant ( ) ) . map_err (
1323
- |e| {
1321
+ |mut e| {
1322
+ e. span_label ( id. span , "while parsing this enum" ) ;
1324
1323
self . recover_stmt ( ) ;
1325
1324
e
1326
1325
} ,
@@ -1347,7 +1346,8 @@ impl<'a> Parser<'a> {
1347
1346
1348
1347
let struct_def = if this. check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
1349
1348
// Parse a struct variant.
1350
- let ( fields, recovered) = this. parse_record_struct_body ( "struct" , false ) ?;
1349
+ let ( fields, recovered) =
1350
+ this. parse_record_struct_body ( "struct" , ident. span , false ) ?;
1351
1351
VariantData :: Struct ( fields, recovered)
1352
1352
} else if this. check ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) {
1353
1353
VariantData :: Tuple ( this. parse_tuple_struct_body ( ) ?, DUMMY_NODE_ID )
@@ -1401,17 +1401,23 @@ impl<'a> Parser<'a> {
1401
1401
VariantData :: Unit ( DUMMY_NODE_ID )
1402
1402
} else {
1403
1403
// If we see: `struct Foo<T> where T: Copy { ... }`
1404
- let ( fields, recovered) =
1405
- 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
+ ) ?;
1406
1409
VariantData :: Struct ( fields, recovered)
1407
1410
}
1408
1411
// No `where` so: `struct Foo<T>;`
1409
1412
} else if self . eat ( & token:: Semi ) {
1410
1413
VariantData :: Unit ( DUMMY_NODE_ID )
1411
1414
// Record-style struct definition
1412
1415
} else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1413
- let ( fields, recovered) =
1414
- 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
+ ) ?;
1415
1421
VariantData :: Struct ( fields, recovered)
1416
1422
// Tuple-style struct definition with optional where-clause.
1417
1423
} else if self . token == token:: OpenDelim ( Delimiter :: Parenthesis ) {
@@ -1440,12 +1446,18 @@ impl<'a> Parser<'a> {
1440
1446
1441
1447
let vdata = if self . token . is_keyword ( kw:: Where ) {
1442
1448
generics. where_clause = self . parse_where_clause ( ) ?;
1443
- let ( fields, recovered) =
1444
- 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
+ ) ?;
1445
1454
VariantData :: Struct ( fields, recovered)
1446
1455
} else if self . token == token:: OpenDelim ( Delimiter :: Brace ) {
1447
- let ( fields, recovered) =
1448
- 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
+ ) ?;
1449
1461
VariantData :: Struct ( fields, recovered)
1450
1462
} else {
1451
1463
let token_str = super :: token_descr ( & self . token ) ;
@@ -1461,6 +1473,7 @@ impl<'a> Parser<'a> {
1461
1473
fn parse_record_struct_body (
1462
1474
& mut self ,
1463
1475
adt_ty : & str ,
1476
+ ident_span : Span ,
1464
1477
parsed_where : bool ,
1465
1478
) -> PResult < ' a , ( Vec < FieldDef > , /* recovered */ bool ) > {
1466
1479
let mut fields = Vec :: new ( ) ;
@@ -1475,6 +1488,7 @@ impl<'a> Parser<'a> {
1475
1488
match field {
1476
1489
Ok ( field) => fields. push ( field) ,
1477
1490
Err ( mut err) => {
1491
+ err. span_label ( ident_span, format ! ( "while parsing this {adt_ty}" ) ) ;
1478
1492
err. emit ( ) ;
1479
1493
break ;
1480
1494
}
0 commit comments