@@ -4,9 +4,9 @@ use super::{
4
4
TokenExpectType , TokenType ,
5
5
} ;
6
6
use crate :: errors:: {
7
- AmbiguousPlus , BadQPathStage2 , BadTypePlus , BadTypePlusSub , ExpectedIdentifier , InInTypo ,
8
- IncorrectAwait , IncorrectSemicolon , IncorrectUseOfAwait , SuggEscapeToUseAsIdentifier ,
9
- SuggRemoveComma , UseEqInstead ,
7
+ AmbiguousPlus , BadQPathStage2 , BadTypePlus , BadTypePlusSub , ExpectedIdentifier , ExpectedSemi ,
8
+ ExpectedSemiSugg , InInTypo , IncorrectAwait , IncorrectSemicolon , IncorrectUseOfAwait ,
9
+ SuggEscapeToUseAsIdentifier , SuggRemoveComma , UseEqInstead ,
10
10
} ;
11
11
12
12
use crate :: lexer:: UnmatchedBrace ;
@@ -388,8 +388,8 @@ impl<'a> Parser<'a> {
388
388
expected. dedup ( ) ;
389
389
390
390
let sm = self . sess . source_map ( ) ;
391
- let msg = format ! ( "expected `;`, found {}" , super :: token_descr ( & self . token ) ) ;
392
- let appl = Applicability :: MachineApplicable ;
391
+
392
+ // Special-case "expected `;`" errors
393
393
if expected. contains ( & TokenType :: Token ( token:: Semi ) ) {
394
394
if self . token . span == DUMMY_SP || self . prev_token . span == DUMMY_SP {
395
395
// Likely inside a macro, can't provide meaningful suggestions.
@@ -417,11 +417,13 @@ impl<'a> Parser<'a> {
417
417
//
418
418
// let x = 32:
419
419
// let y = 42;
420
+ self . sess . emit_err ( ExpectedSemi {
421
+ span : self . token . span ,
422
+ token_descr : super :: token_descr_struct ( & self . token ) ,
423
+ unexpected_token_label : None ,
424
+ sugg : ExpectedSemiSugg :: ChangeToSemi ( self . token . span ) ,
425
+ } ) ;
420
426
self . bump ( ) ;
421
- let sp = self . prev_token . span ;
422
- self . struct_span_err ( sp, & msg)
423
- . span_suggestion_short ( sp, "change this to `;`" , ";" , appl)
424
- . emit ( ) ;
425
427
return Ok ( true ) ;
426
428
} else if self . look_ahead ( 0 , |t| {
427
429
t == & token:: CloseDelim ( Delimiter :: Brace )
@@ -439,11 +441,13 @@ impl<'a> Parser<'a> {
439
441
//
440
442
// let x = 32
441
443
// let y = 42;
442
- let sp = self . prev_token . span . shrink_to_hi ( ) ;
443
- self . struct_span_err ( sp, & msg)
444
- . span_label ( self . token . span , "unexpected token" )
445
- . span_suggestion_short ( sp, "add `;` here" , ";" , appl)
446
- . emit ( ) ;
444
+ let span = self . prev_token . span . shrink_to_hi ( ) ;
445
+ self . sess . emit_err ( ExpectedSemi {
446
+ span,
447
+ token_descr : super :: token_descr_struct ( & self . token ) ,
448
+ unexpected_token_label : Some ( self . token . span ) ,
449
+ sugg : ExpectedSemiSugg :: AddSemi ( span) ,
450
+ } ) ;
447
451
return Ok ( true ) ;
448
452
}
449
453
}
@@ -480,6 +484,7 @@ impl<'a> Parser<'a> {
480
484
)
481
485
} ;
482
486
self . last_unexpected_token_span = Some ( self . token . span ) ;
487
+ // FIXME: translation requires list formatting (for `expect`)
483
488
let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
484
489
485
490
if let TokenKind :: Ident ( symbol, _) = & self . prev_token . kind {
@@ -488,7 +493,7 @@ impl<'a> Parser<'a> {
488
493
self . prev_token . span ,
489
494
& format ! ( "write `fn` instead of `{symbol}` to declare a function" ) ,
490
495
"fn" ,
491
- appl ,
496
+ Applicability :: MachineApplicable ,
492
497
) ;
493
498
}
494
499
}
@@ -502,7 +507,7 @@ impl<'a> Parser<'a> {
502
507
self . prev_token . span ,
503
508
"write `pub` instead of `public` to make the item public" ,
504
509
"pub" ,
505
- appl ,
510
+ Applicability :: MachineApplicable ,
506
511
) ;
507
512
}
508
513
0 commit comments