@@ -3,7 +3,8 @@ use std::num::NonZeroU32;
3
3
use rustc_ast:: token;
4
4
use rustc_ast:: util:: literal:: LitError ;
5
5
use rustc_errors:: {
6
- codes:: * , DiagCtxt , DiagnosticBuilder , DiagnosticMessage , IntoDiagnostic , Level , MultiSpan ,
6
+ codes:: * , DiagCtxt , DiagnosticBuilder , DiagnosticMessage , ErrorGuaranteed , IntoDiagnostic ,
7
+ Level , MultiSpan ,
7
8
} ;
8
9
use rustc_macros:: Diagnostic ;
9
10
use rustc_span:: { Span , Symbol } ;
@@ -344,7 +345,12 @@ pub(crate) struct BinaryFloatLiteralNotSupported {
344
345
pub span : Span ,
345
346
}
346
347
347
- pub fn report_lit_error ( sess : & ParseSess , err : LitError , lit : token:: Lit , span : Span ) {
348
+ pub fn report_lit_error (
349
+ sess : & ParseSess ,
350
+ err : LitError ,
351
+ lit : token:: Lit ,
352
+ span : Span ,
353
+ ) -> ErrorGuaranteed {
348
354
// Checks if `s` looks like i32 or u1234 etc.
349
355
fn looks_like_width_suffix ( first_chars : & [ char ] , s : & str ) -> bool {
350
356
s. len ( ) > 1 && s. starts_with ( first_chars) && s[ 1 ..] . chars ( ) . all ( |c| c. is_ascii_digit ( ) )
@@ -372,44 +378,41 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
372
378
valid. then ( || format ! ( "0{}{}" , base_char. to_ascii_lowercase( ) , & suffix[ 1 ..] ) )
373
379
}
374
380
375
- let token:: Lit { kind, symbol, suffix, .. } = lit;
381
+ let token:: Lit { kind, symbol, suffix } = lit;
376
382
let dcx = & sess. dcx ;
377
383
match err {
378
384
LitError :: InvalidSuffix => {
379
- if let Some ( suffix) = suffix {
380
- dcx. emit_err ( InvalidLiteralSuffix { span, kind : kind. descr ( ) , suffix } ) ;
381
- }
385
+ let suffix = suffix. unwrap ( ) ;
386
+ dcx. emit_err ( InvalidLiteralSuffix { span, kind : kind. descr ( ) , suffix } )
382
387
}
383
388
LitError :: InvalidIntSuffix => {
384
389
let suf = suffix. expect ( "suffix error with no suffix" ) ;
385
390
let suf = suf. as_str ( ) ;
386
391
if looks_like_width_suffix ( & [ 'i' , 'u' ] , suf) {
387
392
// If it looks like a width, try to be helpful.
388
- dcx. emit_err ( InvalidIntLiteralWidth { span, width : suf[ 1 ..] . into ( ) } ) ;
393
+ dcx. emit_err ( InvalidIntLiteralWidth { span, width : suf[ 1 ..] . into ( ) } )
389
394
} else if let Some ( fixed) = fix_base_capitalisation ( symbol. as_str ( ) , suf) {
390
- dcx. emit_err ( InvalidNumLiteralBasePrefix { span, fixed } ) ;
395
+ dcx. emit_err ( InvalidNumLiteralBasePrefix { span, fixed } )
391
396
} else {
392
- dcx. emit_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } ) ;
397
+ dcx. emit_err ( InvalidNumLiteralSuffix { span, suffix : suf. to_string ( ) } )
393
398
}
394
399
}
395
400
LitError :: InvalidFloatSuffix => {
396
401
let suf = suffix. expect ( "suffix error with no suffix" ) ;
397
402
let suf = suf. as_str ( ) ;
398
403
if looks_like_width_suffix ( & [ 'f' ] , suf) {
399
404
// If it looks like a width, try to be helpful.
400
- dcx. emit_err ( InvalidFloatLiteralWidth { span, width : suf[ 1 ..] . to_string ( ) } ) ;
405
+ dcx. emit_err ( InvalidFloatLiteralWidth { span, width : suf[ 1 ..] . to_string ( ) } )
401
406
} else {
402
- dcx. emit_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } ) ;
407
+ dcx. emit_err ( InvalidFloatLiteralSuffix { span, suffix : suf. to_string ( ) } )
403
408
}
404
409
}
405
- LitError :: NonDecimalFloat ( base) => {
406
- match base {
407
- 16 => dcx. emit_err ( HexadecimalFloatLiteralNotSupported { span } ) ,
408
- 8 => dcx. emit_err ( OctalFloatLiteralNotSupported { span } ) ,
409
- 2 => dcx. emit_err ( BinaryFloatLiteralNotSupported { span } ) ,
410
- _ => unreachable ! ( ) ,
411
- } ;
412
- }
410
+ LitError :: NonDecimalFloat ( base) => match base {
411
+ 16 => dcx. emit_err ( HexadecimalFloatLiteralNotSupported { span } ) ,
412
+ 8 => dcx. emit_err ( OctalFloatLiteralNotSupported { span } ) ,
413
+ 2 => dcx. emit_err ( BinaryFloatLiteralNotSupported { span } ) ,
414
+ _ => unreachable ! ( ) ,
415
+ } ,
413
416
LitError :: IntTooLarge ( base) => {
414
417
let max = u128:: MAX ;
415
418
let limit = match base {
@@ -418,7 +421,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
418
421
16 => format ! ( "{max:#x}" ) ,
419
422
_ => format ! ( "{max}" ) ,
420
423
} ;
421
- dcx. emit_err ( IntLiteralTooLarge { span, limit } ) ;
424
+ dcx. emit_err ( IntLiteralTooLarge { span, limit } )
422
425
}
423
426
}
424
427
}
0 commit comments