@@ -1780,9 +1780,7 @@ impl<'a> Parser<'a> {
1780
1780
if self . eat ( & token:: DotDot ) {
1781
1781
let exp_span = self . prev_span ;
1782
1782
match self . parse_expr ( ) {
1783
- Ok ( e) => {
1784
- base = Some ( e) ;
1785
- }
1783
+ Ok ( e) => base = Some ( e) ,
1786
1784
Err ( mut e) => {
1787
1785
e. emit ( ) ;
1788
1786
self . recover_stmt ( ) ;
@@ -1792,24 +1790,9 @@ impl<'a> Parser<'a> {
1792
1790
break ;
1793
1791
}
1794
1792
1795
- let mut recovery_field = None ;
1796
- if let token:: Ident ( name, _) = self . token . kind {
1797
- if !self . token . is_reserved_ident ( ) && self . look_ahead ( 1 , |t| * t == token:: Colon ) {
1798
- // Use in case of error after field-looking code: `S { foo: () with a }`.
1799
- recovery_field = Some ( ast:: Field {
1800
- ident : Ident :: new ( name, self . token . span ) ,
1801
- span : self . token . span ,
1802
- expr : self . mk_expr ( self . token . span , ExprKind :: Err , AttrVec :: new ( ) ) ,
1803
- is_shorthand : false ,
1804
- attrs : AttrVec :: new ( ) ,
1805
- id : DUMMY_NODE_ID ,
1806
- is_placeholder : false ,
1807
- } ) ;
1808
- }
1809
- }
1810
- let mut parsed_field = None ;
1811
- match self . parse_field ( ) {
1812
- Ok ( f) => parsed_field = Some ( f) ,
1793
+ let recovery_field = self . find_struct_error_after_field_looking_code ( ) ;
1794
+ let parsed_field = match self . parse_field ( ) {
1795
+ Ok ( f) => Some ( f) ,
1813
1796
Err ( mut e) => {
1814
1797
e. span_label ( struct_sp, "while parsing this struct" ) ;
1815
1798
e. emit ( ) ;
@@ -1823,8 +1806,9 @@ impl<'a> Parser<'a> {
1823
1806
break ;
1824
1807
}
1825
1808
}
1809
+ None
1826
1810
}
1827
- }
1811
+ } ;
1828
1812
1829
1813
match self . expect_one_of ( & [ token:: Comma ] , & [ token:: CloseDelim ( token:: Brace ) ] ) {
1830
1814
Ok ( _) => {
@@ -1847,7 +1831,26 @@ impl<'a> Parser<'a> {
1847
1831
1848
1832
let span = lo. to ( self . token . span ) ;
1849
1833
self . expect ( & token:: CloseDelim ( token:: Brace ) ) ?;
1850
- return Ok ( self . mk_expr ( span, ExprKind :: Struct ( pth, fields, base) , attrs) ) ;
1834
+ Ok ( self . mk_expr ( span, ExprKind :: Struct ( pth, fields, base) , attrs) )
1835
+ }
1836
+
1837
+ /// Use in case of error after field-looking code: `S { foo: () with a }`.
1838
+ fn find_struct_error_after_field_looking_code ( & self ) -> Option < Field > {
1839
+ if let token:: Ident ( name, _) = self . token . kind {
1840
+ if !self . token . is_reserved_ident ( ) && self . look_ahead ( 1 , |t| * t == token:: Colon ) {
1841
+ let span = self . token . span ;
1842
+ return Some ( ast:: Field {
1843
+ ident : Ident :: new ( name, span) ,
1844
+ span,
1845
+ expr : self . mk_expr_err ( span) ,
1846
+ is_shorthand : false ,
1847
+ attrs : AttrVec :: new ( ) ,
1848
+ id : DUMMY_NODE_ID ,
1849
+ is_placeholder : false ,
1850
+ } ) ;
1851
+ }
1852
+ }
1853
+ None
1851
1854
}
1852
1855
1853
1856
fn recover_struct_comma_after_dotdot ( & mut self , span : Span ) {
0 commit comments