@@ -295,6 +295,17 @@ struct BadQPathStage2 {
295
295
ty : String ,
296
296
}
297
297
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
+
298
309
// SnapshotParser is used to create a snapshot of the parser
299
310
// without causing duplicate errors being emitted when the `Parser`
300
311
// is dropped.
@@ -1490,13 +1501,10 @@ impl<'a> Parser<'a> {
1490
1501
pub fn maybe_consume_incorrect_semicolon ( & mut self , items : & [ P < Item > ] ) -> bool {
1491
1502
if self . token . kind == TokenKind :: Semi {
1492
1503
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
+
1500
1508
if !items. is_empty ( ) {
1501
1509
let previous_item = & items[ items. len ( ) - 1 ] ;
1502
1510
let previous_item_kind_name = match previous_item. kind {
@@ -1509,10 +1517,11 @@ impl<'a> Parser<'a> {
1509
1517
_ => None ,
1510
1518
} ;
1511
1519
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;
1513
1522
}
1514
1523
}
1515
- err . emit ( ) ;
1524
+ self . sess . emit_err ( err ) ;
1516
1525
true
1517
1526
} else {
1518
1527
false
0 commit comments