@@ -458,8 +458,11 @@ fn lint_int_literal<'tcx>(
458
458
}
459
459
460
460
let span = if negative { type_limits. negated_expr_span . unwrap ( ) } else { e. span } ;
461
- let lit =
462
- cx. sess ( ) . source_map ( ) . span_to_snippet ( span) . expect ( "must get snippet from literal" ) ;
461
+ let lit = cx
462
+ . sess ( )
463
+ . source_map ( )
464
+ . span_to_snippet ( span)
465
+ . unwrap_or_else ( |_| if negative { format ! ( "-{v}" ) } else { v. to_string ( ) } ) ;
463
466
let help = get_type_suggestion ( cx. typeck_results ( ) . node_type ( e. hir_id ) , v, negative)
464
467
. map ( |suggestion_ty| OverflowingIntHelp { suggestion_ty } ) ;
465
468
@@ -485,6 +488,7 @@ fn lint_uint_literal<'tcx>(
485
488
ast:: LitKind :: Int ( v, _) => v. get ( ) ,
486
489
_ => bug ! ( ) ,
487
490
} ;
491
+
488
492
if lit_val < min || lit_val > max {
489
493
if let Node :: Expr ( par_e) = cx. tcx . parent_hir_node ( e. hir_id ) {
490
494
match par_e. kind {
@@ -526,7 +530,7 @@ fn lint_uint_literal<'tcx>(
526
530
. sess ( )
527
531
. source_map ( )
528
532
. span_to_snippet ( lit. span )
529
- . expect ( "must get snippet from literal" ) ,
533
+ . unwrap_or_else ( |_| lit_val . to_string ( ) ) ,
530
534
min,
531
535
max,
532
536
} ,
@@ -551,14 +555,14 @@ fn lint_literal<'tcx>(
551
555
}
552
556
ty:: Uint ( t) => lint_uint_literal ( cx, e, lit, t) ,
553
557
ty:: Float ( t) => {
554
- let is_infinite = match lit. node {
558
+ let ( is_infinite, sym ) = match lit. node {
555
559
ast:: LitKind :: Float ( v, _) => match t {
556
560
// FIXME(f16_f128): add this check once `is_infinite` is reliable (ABI
557
561
// issues resolved).
558
- ty:: FloatTy :: F16 => Ok ( false ) ,
559
- ty:: FloatTy :: F32 => v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) ,
560
- ty:: FloatTy :: F64 => v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) ,
561
- ty:: FloatTy :: F128 => Ok ( false ) ,
562
+ ty:: FloatTy :: F16 => ( Ok ( false ) , v ) ,
563
+ ty:: FloatTy :: F32 => ( v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) , v ) ,
564
+ ty:: FloatTy :: F64 => ( v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) , v ) ,
565
+ ty:: FloatTy :: F128 => ( Ok ( false ) , v ) ,
562
566
} ,
563
567
_ => bug ! ( ) ,
564
568
} ;
@@ -572,7 +576,7 @@ fn lint_literal<'tcx>(
572
576
. sess ( )
573
577
. source_map ( )
574
578
. span_to_snippet ( lit. span )
575
- . expect ( "must get snippet from literal" ) ,
579
+ . unwrap_or_else ( |_| sym . to_string ( ) ) ,
576
580
} ,
577
581
) ;
578
582
}
0 commit comments