@@ -458,8 +458,11 @@ fn lint_int_literal<'tcx>(
458458 }
459459
460460 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 ( ) } ) ;
463466 let help = get_type_suggestion ( cx. typeck_results ( ) . node_type ( e. hir_id ) , v, negative)
464467 . map ( |suggestion_ty| OverflowingIntHelp { suggestion_ty } ) ;
465468
@@ -485,6 +488,7 @@ fn lint_uint_literal<'tcx>(
485488 ast:: LitKind :: Int ( v, _) => v. get ( ) ,
486489 _ => bug ! ( ) ,
487490 } ;
491+
488492 if lit_val < min || lit_val > max {
489493 if let Node :: Expr ( par_e) = cx. tcx . parent_hir_node ( e. hir_id ) {
490494 match par_e. kind {
@@ -526,7 +530,7 @@ fn lint_uint_literal<'tcx>(
526530 . sess ( )
527531 . source_map ( )
528532 . span_to_snippet ( lit. span )
529- . expect ( "must get snippet from literal" ) ,
533+ . unwrap_or_else ( |_| lit_val . to_string ( ) ) ,
530534 min,
531535 max,
532536 } ,
@@ -551,14 +555,14 @@ fn lint_literal<'tcx>(
551555 }
552556 ty:: Uint ( t) => lint_uint_literal ( cx, e, lit, t) ,
553557 ty:: Float ( t) => {
554- let is_infinite = match lit. node {
558+ let ( is_infinite, sym ) = match lit. node {
555559 ast:: LitKind :: Float ( v, _) => match t {
556560 // FIXME(f16_f128): add this check once `is_infinite` is reliable (ABI
557561 // 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 ) ,
562566 } ,
563567 _ => bug ! ( ) ,
564568 } ;
@@ -572,7 +576,7 @@ fn lint_literal<'tcx>(
572576 . sess ( )
573577 . source_map ( )
574578 . span_to_snippet ( lit. span )
575- . expect ( "must get snippet from literal" ) ,
579+ . unwrap_or_else ( |_| sym . to_string ( ) ) ,
576580 } ,
577581 ) ;
578582 }
0 commit comments