1
- use crate :: errors;
2
-
3
1
use super :: diagnostics:: { dummy_arg, ConsumeClosingDelim } ;
4
2
use super :: ty:: { AllowPlus , RecoverQPath , RecoverReturnSign } ;
5
3
use super :: { AttrWrapper , FollowedByType , ForceCollect , Parser , PathStyle , TrailingToken } ;
4
+ use crate :: errors:: { self , MacroExpandsToAdtField } ;
5
+ use crate :: fluent_generated as fluent;
6
6
use ast:: StaticItem ;
7
7
use rustc_ast:: ast:: * ;
8
8
use rustc_ast:: ptr:: P ;
@@ -1450,6 +1450,17 @@ impl<'a> Parser<'a> {
1450
1450
}
1451
1451
let ident = this. parse_field_ident ( "enum" , vlo) ?;
1452
1452
1453
+ if this. token == token:: Not {
1454
+ if let Err ( mut err) = this. unexpected :: < ( ) > ( ) {
1455
+ err. note ( fluent:: parse_macro_expands_to_enum_variant) . emit ( ) ;
1456
+ }
1457
+
1458
+ this. bump ( ) ;
1459
+ this. parse_delim_args ( ) ?;
1460
+
1461
+ return Ok ( ( None , TrailingToken :: MaybeComma ) ) ;
1462
+ }
1463
+
1453
1464
let struct_def = if this. check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
1454
1465
// Parse a struct variant.
1455
1466
let ( fields, recovered) =
@@ -1477,7 +1488,7 @@ impl<'a> Parser<'a> {
1477
1488
1478
1489
Ok ( ( Some ( vr) , TrailingToken :: MaybeComma ) )
1479
1490
} ,
1480
- ) . map_err ( |mut err|{
1491
+ ) . map_err ( |mut err| {
1481
1492
err. help ( "enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`" ) ;
1482
1493
err
1483
1494
} )
@@ -1687,7 +1698,8 @@ impl<'a> Parser<'a> {
1687
1698
self . collect_tokens_trailing_token ( attrs, ForceCollect :: No , |this, attrs| {
1688
1699
let lo = this. token . span ;
1689
1700
let vis = this. parse_visibility ( FollowedByType :: No ) ?;
1690
- Ok ( ( this. parse_single_struct_field ( adt_ty, lo, vis, attrs) ?, TrailingToken :: None ) )
1701
+ this. parse_single_struct_field ( adt_ty, lo, vis, attrs)
1702
+ . map ( |field| ( field, TrailingToken :: None ) )
1691
1703
} )
1692
1704
}
1693
1705
@@ -1821,8 +1833,8 @@ impl<'a> Parser<'a> {
1821
1833
"field names and their types are separated with `:`" ,
1822
1834
":" ,
1823
1835
Applicability :: MachineApplicable ,
1824
- ) ;
1825
- err . emit ( ) ;
1836
+ )
1837
+ . emit ( ) ;
1826
1838
} else {
1827
1839
return Err ( err) ;
1828
1840
}
@@ -1839,6 +1851,23 @@ impl<'a> Parser<'a> {
1839
1851
attrs : AttrVec ,
1840
1852
) -> PResult < ' a , FieldDef > {
1841
1853
let name = self . parse_field_ident ( adt_ty, lo) ?;
1854
+ // Parse the macro invocation and recover
1855
+ if self . token . kind == token:: Not {
1856
+ if let Err ( mut err) = self . unexpected :: < FieldDef > ( ) {
1857
+ err. subdiagnostic ( MacroExpandsToAdtField { adt_ty } ) . emit ( ) ;
1858
+ self . bump ( ) ;
1859
+ self . parse_delim_args ( ) ?;
1860
+ return Ok ( FieldDef {
1861
+ span : DUMMY_SP ,
1862
+ ident : None ,
1863
+ vis,
1864
+ id : DUMMY_NODE_ID ,
1865
+ ty : self . mk_ty ( DUMMY_SP , TyKind :: Err ) ,
1866
+ attrs,
1867
+ is_placeholder : false ,
1868
+ } ) ;
1869
+ }
1870
+ }
1842
1871
self . expect_field_ty_separator ( ) ?;
1843
1872
let ty = self . parse_ty ( ) ?;
1844
1873
if self . token . kind == token:: Colon && self . look_ahead ( 1 , |tok| tok. kind != token:: Colon ) {
0 commit comments