@@ -384,6 +384,10 @@ pub fn report_lit_error(
384384 lit : token:: Lit ,
385385 span : Span ,
386386) -> 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 < ' _ > {
387391 // Checks if `s` looks like i32 or u1234 etc.
388392 fn looks_like_width_suffix ( first_chars : & [ char ] , s : & str ) -> bool {
389393 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(
414418 let dcx = psess. dcx ( ) ;
415419 match err {
416420 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 } )
418422 }
419423 LitError :: InvalidIntSuffix ( suffix) => {
420424 let suf = suffix. as_str ( ) ;
421425 if looks_like_width_suffix ( & [ 'i' , 'u' ] , suf) {
422426 // 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 ( ) } )
424428 } 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 } )
426430 } else {
427- dcx. emit_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } )
431+ dcx. create_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } )
428432 }
429433 }
430434 LitError :: InvalidFloatSuffix ( suffix) => {
431435 let suf = suffix. as_str ( ) ;
432436 if looks_like_width_suffix ( & [ 'f' ] , suf) {
433437 // 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 ( ) } )
435439 } else {
436- dcx. emit_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } )
440+ dcx. create_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } )
437441 }
438442 }
439443 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 } ) ,
443447 _ => unreachable ! ( ) ,
444448 } ,
445449 LitError :: IntTooLarge ( base) => {
@@ -450,7 +454,7 @@ pub fn report_lit_error(
450454 16 => format ! ( "{max:#x}" ) ,
451455 _ => format ! ( "{max}" ) ,
452456 } ;
453- dcx. emit_err ( IntLiteralTooLarge { span, limit } )
457+ dcx. create_err ( IntLiteralTooLarge { span, limit } )
454458 }
455459 }
456460}
0 commit comments