@@ -295,6 +295,17 @@ struct BadQPathStage2 {
295295 ty : String ,
296296}
297297
298+ #[ derive( SessionDiagnostic ) ]
299+ #[ error( slug = "parser-incorrect-semicolon" ) ]
300+ struct IncorrectSemicolon < ' a > {
301+ #[ primary_span]
302+ #[ suggestion( applicability = "machine-applicable" ) ]
303+ span : Span ,
304+ #[ help]
305+ opt_help : Option < ( ) > ,
306+ name : & ' a str ,
307+ }
308+
298309// SnapshotParser is used to create a snapshot of the parser
299310// without causing duplicate errors being emitted when the `Parser`
300311// is dropped.
@@ -1490,13 +1501,10 @@ impl<'a> Parser<'a> {
14901501 pub fn maybe_consume_incorrect_semicolon ( & mut self , items : & [ P < Item > ] ) -> bool {
14911502 if self . token . kind == TokenKind :: Semi {
14921503 self . bump ( ) ;
1493- let mut err = self . struct_span_err ( self . prev_token . span , "expected item, found `;`" ) ;
1494- err. span_suggestion_short (
1495- self . prev_token . span ,
1496- "remove this semicolon" ,
1497- String :: new ( ) ,
1498- Applicability :: MachineApplicable ,
1499- ) ;
1504+
1505+ let mut err =
1506+ IncorrectSemicolon { span : self . prev_token . span , opt_help : None , name : "" } ;
1507+
15001508 if !items. is_empty ( ) {
15011509 let previous_item = & items[ items. len ( ) - 1 ] ;
15021510 let previous_item_kind_name = match previous_item. kind {
@@ -1509,10 +1517,11 @@ impl<'a> Parser<'a> {
15091517 _ => None ,
15101518 } ;
15111519 if let Some ( name) = previous_item_kind_name {
1512- err. help ( & format ! ( "{name} declarations are not followed by a semicolon" ) ) ;
1520+ err. opt_help = Some ( ( ) ) ;
1521+ err. name = name;
15131522 }
15141523 }
1515- err . emit ( ) ;
1524+ self . sess . emit_err ( err ) ;
15161525 true
15171526 } else {
15181527 false
0 commit comments