@@ -1817,34 +1817,31 @@ impl<'a> Parser<'a> {
1817
1817
Ok ( P ( T :: recovered ( Some ( P ( QSelf { ty, path_span, position : 0 } ) ) , path) ) )
1818
1818
}
1819
1819
1820
- pub fn maybe_consume_incorrect_semicolon ( & mut self , items : & [ P < Item > ] ) -> bool {
1821
- if self . token . kind == TokenKind :: Semi {
1822
- self . bump ( ) ;
1823
-
1824
- let mut err =
1825
- IncorrectSemicolon { span : self . prev_token . span , opt_help : None , name : "" } ;
1820
+ /// This function gets called in places where a semicolon is NOT expected and if there's a
1821
+ /// semicolon it emits the appropriate error and returns true.
1822
+ pub fn maybe_consume_incorrect_semicolon ( & mut self , previous_item : Option < & Item > ) -> bool {
1823
+ if self . token . kind != TokenKind :: Semi {
1824
+ return false ;
1825
+ }
1826
1826
1827
- if !items. is_empty ( ) {
1828
- let previous_item = & items[ items. len ( ) - 1 ] ;
1829
- let previous_item_kind_name = match previous_item. kind {
1827
+ // Check previous item to add it to the diagnostic, for example to say
1828
+ // `enum declarations are not followed by a semicolon`
1829
+ let err = match previous_item {
1830
+ Some ( previous_item) => {
1831
+ let name = match previous_item. kind {
1830
1832
// Say "braced struct" because tuple-structs and
1831
1833
// braceless-empty-struct declarations do take a semicolon.
1832
- ItemKind :: Struct ( ..) => Some ( "braced struct" ) ,
1833
- ItemKind :: Enum ( ..) => Some ( "enum" ) ,
1834
- ItemKind :: Trait ( ..) => Some ( "trait" ) ,
1835
- ItemKind :: Union ( ..) => Some ( "union" ) ,
1836
- _ => None ,
1834
+ ItemKind :: Struct ( ..) => "braced struct" ,
1835
+ _ => previous_item. kind . descr ( ) ,
1837
1836
} ;
1838
- if let Some ( name) = previous_item_kind_name {
1839
- err. opt_help = Some ( ( ) ) ;
1840
- err. name = name;
1841
- }
1837
+ IncorrectSemicolon { span : self . token . span , name, show_help : true }
1842
1838
}
1843
- self . dcx ( ) . emit_err ( err) ;
1844
- true
1845
- } else {
1846
- false
1847
- }
1839
+ None => IncorrectSemicolon { span : self . token . span , name : "" , show_help : false } ,
1840
+ } ;
1841
+ self . dcx ( ) . emit_err ( err) ;
1842
+
1843
+ self . bump ( ) ;
1844
+ true
1848
1845
}
1849
1846
1850
1847
/// Creates a `Diag` for an unexpected token `t` and tries to recover if it is a
0 commit comments