@@ -2695,28 +2695,12 @@ impl<'a> Parser<'a> {
26952695 break ;
26962696 }
26972697
2698- let mut recovery_field = None ;
2699- if let token:: Ident ( ident, _) = self . token {
2700- if !self . token . is_reserved_ident ( ) {
2701- let mut ident = ident. clone ( ) ;
2702- ident. span = self . span ;
2703- recovery_field = Some ( ast:: Field {
2704- ident,
2705- span : self . span ,
2706- expr : self . mk_expr ( self . span , ExprKind :: Err , ThinVec :: new ( ) ) ,
2707- is_shorthand : true ,
2708- attrs : ThinVec :: new ( ) ,
2709- } ) ;
2710- }
2711- }
2698+ let mut parsed_field = None ;
27122699 match self . parse_field ( ) {
2713- Ok ( f) => fields . push ( f) ,
2700+ Ok ( f) => parsed_field = Some ( f) ,
27142701 Err ( mut e) => {
27152702 e. span_label ( struct_sp, "while parsing this struct" ) ;
27162703 e. emit ( ) ;
2717- if let Some ( f) = recovery_field {
2718- fields. push ( f) ;
2719- }
27202704
27212705 // If the next token is a comma, then try to parse
27222706 // what comes next as additional fields, rather than
@@ -2732,7 +2716,10 @@ impl<'a> Parser<'a> {
27322716
27332717 match self . expect_one_of ( & [ token:: Comma ] ,
27342718 & [ token:: CloseDelim ( token:: Brace ) ] ) {
2735- Ok ( ( ) ) => { }
2719+ Ok ( ( ) ) => if let Some ( f) = parsed_field {
2720+ // only include the field if there's no parse error
2721+ fields. push ( f) ;
2722+ }
27362723 Err ( mut e) => {
27372724 e. span_label ( struct_sp, "while parsing this struct" ) ;
27382725 e. emit ( ) ;
0 commit comments