@@ -462,8 +462,11 @@ fn lint_int_literal<'tcx>(
462
462
}
463
463
464
464
let span = if negative { type_limits. negated_expr_span . unwrap ( ) } else { e. span } ;
465
- let lit =
466
- cx. sess ( ) . source_map ( ) . span_to_snippet ( span) . expect ( "must get snippet from literal" ) ;
465
+ let lit = cx
466
+ . sess ( )
467
+ . source_map ( )
468
+ . span_to_snippet ( span)
469
+ . unwrap_or_else ( |_| if negative { format ! ( "-{v}" ) } else { v. to_string ( ) } ) ;
467
470
let help = get_type_suggestion ( cx. typeck_results ( ) . node_type ( e. hir_id ) , v, negative)
468
471
. map ( |suggestion_ty| OverflowingIntHelp { suggestion_ty } ) ;
469
472
@@ -489,6 +492,7 @@ fn lint_uint_literal<'tcx>(
489
492
ast:: LitKind :: Int ( v, _) => v. get ( ) ,
490
493
_ => bug ! ( ) ,
491
494
} ;
495
+
492
496
if lit_val < min || lit_val > max {
493
497
if let Node :: Expr ( par_e) = cx. tcx . parent_hir_node ( e. hir_id ) {
494
498
match par_e. kind {
@@ -530,7 +534,7 @@ fn lint_uint_literal<'tcx>(
530
534
. sess ( )
531
535
. source_map ( )
532
536
. span_to_snippet ( lit. span )
533
- . expect ( "must get snippet from literal" ) ,
537
+ . unwrap_or_else ( |_| lit_val . to_string ( ) ) ,
534
538
min,
535
539
max,
536
540
} ,
@@ -555,14 +559,14 @@ fn lint_literal<'tcx>(
555
559
}
556
560
ty:: Uint ( t) => lint_uint_literal ( cx, e, lit, t) ,
557
561
ty:: Float ( t) => {
558
- let is_infinite = match lit. node {
562
+ let ( is_infinite, sym ) = match lit. node {
559
563
ast:: LitKind :: Float ( v, _) => match t {
560
564
// FIXME(f16_f128): add this check once `is_infinite` is reliable (ABI
561
565
// issues resolved).
562
- ty:: FloatTy :: F16 => Ok ( false ) ,
563
- ty:: FloatTy :: F32 => v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) ,
564
- ty:: FloatTy :: F64 => v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) ,
565
- ty:: FloatTy :: F128 => Ok ( false ) ,
566
+ ty:: FloatTy :: F16 => ( Ok ( false ) , v ) ,
567
+ ty:: FloatTy :: F32 => ( v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) , v ) ,
568
+ ty:: FloatTy :: F64 => ( v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) , v ) ,
569
+ ty:: FloatTy :: F128 => ( Ok ( false ) , v ) ,
566
570
} ,
567
571
_ => bug ! ( ) ,
568
572
} ;
@@ -576,7 +580,7 @@ fn lint_literal<'tcx>(
576
580
. sess ( )
577
581
. source_map ( )
578
582
. span_to_snippet ( lit. span )
579
- . expect ( "must get snippet from literal" ) ,
583
+ . unwrap_or_else ( |_| sym . to_string ( ) ) ,
580
584
} ,
581
585
) ;
582
586
}
0 commit comments