@@ -384,6 +384,10 @@ pub fn report_lit_error(
384
384
lit : token:: Lit ,
385
385
span : Span ,
386
386
) -> ErrorGuaranteed {
387
+ create_lit_error ( psess, err, lit, span) . emit ( )
388
+ }
389
+
390
+ pub fn create_lit_error ( psess : & ParseSess , err : LitError , lit : token:: Lit , span : Span ) -> Diag < ' _ > {
387
391
// Checks if `s` looks like i32 or u1234 etc.
388
392
fn looks_like_width_suffix ( first_chars : & [ char ] , s : & str ) -> bool {
389
393
s. len ( ) > 1 && s. starts_with ( first_chars) && s[ 1 ..] . chars ( ) . all ( |c| c. is_ascii_digit ( ) )
@@ -414,32 +418,32 @@ pub fn report_lit_error(
414
418
let dcx = psess. dcx ( ) ;
415
419
match err {
416
420
LitError :: InvalidSuffix ( suffix) => {
417
- dcx. emit_err ( InvalidLiteralSuffix { span, kind : lit. kind . descr ( ) , suffix } )
421
+ dcx. create_err ( InvalidLiteralSuffix { span, kind : lit. kind . descr ( ) , suffix } )
418
422
}
419
423
LitError :: InvalidIntSuffix ( suffix) => {
420
424
let suf = suffix. as_str ( ) ;
421
425
if looks_like_width_suffix ( & [ 'i' , 'u' ] , suf) {
422
426
// If it looks like a width, try to be helpful.
423
- dcx. emit_err ( InvalidIntLiteralWidth { span, width : suf[ 1 ..] . into ( ) } )
427
+ dcx. create_err ( InvalidIntLiteralWidth { span, width : suf[ 1 ..] . into ( ) } )
424
428
} else if let Some ( fixed) = fix_base_capitalisation ( lit. symbol . as_str ( ) , suf) {
425
- dcx. emit_err ( InvalidNumLiteralBasePrefix { span, fixed } )
429
+ dcx. create_err ( InvalidNumLiteralBasePrefix { span, fixed } )
426
430
} else {
427
- dcx. emit_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } )
431
+ dcx. create_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } )
428
432
}
429
433
}
430
434
LitError :: InvalidFloatSuffix ( suffix) => {
431
435
let suf = suffix. as_str ( ) ;
432
436
if looks_like_width_suffix ( & [ 'f' ] , suf) {
433
437
// If it looks like a width, try to be helpful.
434
- dcx. emit_err ( InvalidFloatLiteralWidth { span, width : suf[ 1 ..] . to_string ( ) } )
438
+ dcx. create_err ( InvalidFloatLiteralWidth { span, width : suf[ 1 ..] . to_string ( ) } )
435
439
} else {
436
- dcx. emit_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } )
440
+ dcx. create_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } )
437
441
}
438
442
}
439
443
LitError :: NonDecimalFloat ( base) => match base {
440
- 16 => dcx. emit_err ( HexadecimalFloatLiteralNotSupported { span } ) ,
441
- 8 => dcx. emit_err ( OctalFloatLiteralNotSupported { span } ) ,
442
- 2 => dcx. emit_err ( BinaryFloatLiteralNotSupported { span } ) ,
444
+ 16 => dcx. create_err ( HexadecimalFloatLiteralNotSupported { span } ) ,
445
+ 8 => dcx. create_err ( OctalFloatLiteralNotSupported { span } ) ,
446
+ 2 => dcx. create_err ( BinaryFloatLiteralNotSupported { span } ) ,
443
447
_ => unreachable ! ( ) ,
444
448
} ,
445
449
LitError :: IntTooLarge ( base) => {
@@ -450,7 +454,7 @@ pub fn report_lit_error(
450
454
16 => format ! ( "{max:#x}" ) ,
451
455
_ => format ! ( "{max}" ) ,
452
456
} ;
453
- dcx. emit_err ( IntLiteralTooLarge { span, limit } )
457
+ dcx. create_err ( IntLiteralTooLarge { span, limit } )
454
458
}
455
459
}
456
460
}
0 commit comments