@@ -419,6 +419,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
419
419
if needs_paren { "(" } else { "" } ,
420
420
src,
421
421
if needs_paren { ")" } else { "" } ) ;
422
+ let suffix_suggestion = format ! (
423
+ "{}{}{}{}" ,
424
+ if needs_paren { "(" } else { "" } ,
425
+ src,
426
+ expected_ty,
427
+ if needs_paren { ")" } else { "" } ,
428
+ ) ;
429
+
430
+ let is_suffixed = |expr : & hir:: Expr | {
431
+ if let hir:: ExprKind :: Lit ( lit) = & expr. node {
432
+ lit. node . is_suffixed ( )
433
+ } else {
434
+ false
435
+ }
436
+ } ;
422
437
423
438
match ( & expected_ty. sty , & checked_ty. sty ) {
424
439
( & ty:: Int ( ref exp) , & ty:: Int ( ref found) ) => {
@@ -444,12 +459,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
444
459
}
445
460
}
446
461
_ => {
447
- err. span_suggestion_with_applicability (
448
- expr. span ,
449
- & format ! ( "{}, which {}" , msg, will_sign_extend) ,
450
- into_suggestion,
451
- Applicability :: MachineApplicable
452
- ) ;
462
+ if is_suffixed ( expr) {
463
+ err. span_suggestion_with_applicability (
464
+ expr. span ,
465
+ & format ! (
466
+ "change the type of the numeric literal from `{}` to `{}`" ,
467
+ checked_ty,
468
+ expected_ty,
469
+ ) ,
470
+ suffix_suggestion,
471
+ Applicability :: MaybeIncorrect ,
472
+ ) ;
473
+ } else {
474
+ err. span_suggestion_with_applicability (
475
+ expr. span ,
476
+ & format ! ( "{}, which {}" , msg, will_sign_extend) ,
477
+ into_suggestion,
478
+ Applicability :: MachineApplicable
479
+ ) ;
480
+ }
453
481
}
454
482
}
455
483
true
@@ -477,12 +505,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
477
505
}
478
506
}
479
507
_ => {
480
- err. span_suggestion_with_applicability (
481
- expr. span ,
482
- & format ! ( "{}, which {}" , msg, will_zero_extend) ,
483
- into_suggestion,
484
- Applicability :: MachineApplicable
485
- ) ;
508
+ if is_suffixed ( expr) {
509
+ err. span_suggestion_with_applicability (
510
+ expr. span ,
511
+ & format ! (
512
+ "change the type of the numeric literal from `{}` to `{}`" ,
513
+ checked_ty,
514
+ expected_ty,
515
+ ) ,
516
+ suffix_suggestion,
517
+ Applicability :: MaybeIncorrect ,
518
+ ) ;
519
+ } else {
520
+ err. span_suggestion_with_applicability (
521
+ expr. span ,
522
+ & format ! ( "{}, which {}" , msg, will_zero_extend) ,
523
+ into_suggestion,
524
+ Applicability :: MachineApplicable
525
+ ) ;
526
+ }
486
527
}
487
528
}
488
529
true
@@ -583,12 +624,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
583
624
}
584
625
( & ty:: Float ( ref exp) , & ty:: Float ( ref found) ) => {
585
626
if found. bit_width ( ) < exp. bit_width ( ) {
586
- err. span_suggestion_with_applicability (
587
- expr. span ,
588
- & format ! ( "{} in a lossless way" , msg) ,
589
- into_suggestion,
590
- Applicability :: MachineApplicable
591
- ) ;
627
+ if is_suffixed ( expr) {
628
+ err. span_suggestion_with_applicability (
629
+ expr. span ,
630
+ & format ! (
631
+ "change the type of the numeric literal from `{}` to `{}`" ,
632
+ checked_ty,
633
+ expected_ty,
634
+ ) ,
635
+ suffix_suggestion,
636
+ Applicability :: MaybeIncorrect ,
637
+ ) ;
638
+ } else {
639
+ err. span_suggestion_with_applicability (
640
+ expr. span ,
641
+ & format ! ( "{} in a lossless way" , msg) ,
642
+ into_suggestion,
643
+ Applicability :: MachineApplicable
644
+ ) ;
645
+ }
592
646
} else if can_cast {
593
647
err. span_suggestion_with_applicability (
594
648
expr. span ,
0 commit comments