@@ -323,7 +323,9 @@ impl<'a, 'tcx> CastCheck<'tcx> {
323
323
}
324
324
CastError :: CastToBool => {
325
325
let help = if self . expr_ty . is_numeric ( ) {
326
- errors:: CannotCastToBoolHelp :: Numeric ( self . expr_span . shrink_to_hi ( ) . with_hi ( self . span . hi ( ) ) )
326
+ errors:: CannotCastToBoolHelp :: Numeric (
327
+ self . expr_span . shrink_to_hi ( ) . with_hi ( self . span . hi ( ) ) ,
328
+ )
327
329
} else {
328
330
errors:: CannotCastToBoolHelp :: Unsupported ( self . span )
329
331
} ;
@@ -520,33 +522,20 @@ impl<'a, 'tcx> CastCheck<'tcx> {
520
522
. emit ( ) ;
521
523
}
522
524
CastError :: IntToFatCast ( known_metadata) => {
523
- let mut err = struct_span_err ! (
524
- fcx. tcx. sess,
525
- self . cast_span,
526
- E0606 ,
527
- "cannot cast `{}` to a pointer that {} wide" ,
528
- fcx. ty_to_string( self . expr_ty) ,
529
- if known_metadata. is_some( ) { "is" } else { "may be" }
530
- ) ;
531
-
532
- err. span_label (
533
- self . cast_span ,
534
- format ! (
535
- "creating a `{}` requires both an address and {}" ,
536
- self . cast_ty,
537
- known_metadata. unwrap_or( "type-specific metadata" ) ,
538
- ) ,
539
- ) ;
540
-
541
- if fcx. tcx . sess . is_nightly_build ( ) {
542
- err. span_label (
543
- self . expr_span ,
544
- "consider casting this expression to `*const ()`, \
545
- then using `core::ptr::from_raw_parts`",
546
- ) ;
547
- }
548
-
549
- err. emit ( ) ;
525
+ let expr_if_nightly = fcx. tcx . sess . is_nightly_build ( ) . then_some ( self . expr_span ) ;
526
+ let cast_ty = self . cast_ty ;
527
+ let expr_ty = fcx. ty_to_string ( self . expr_ty ) ;
528
+ let metadata = known_metadata. unwrap_or ( "type-specific metadata" ) ;
529
+ let known_wide = known_metadata. is_some ( ) ;
530
+ let span = self . cast_span ;
531
+ fcx. tcx . sess . emit_err ( errors:: IntToWide {
532
+ span,
533
+ metadata,
534
+ expr_ty,
535
+ cast_ty,
536
+ expr_if_nightly,
537
+ known_wide,
538
+ } ) ;
550
539
}
551
540
CastError :: UnknownCastPtrKind | CastError :: UnknownExprPtrKind => {
552
541
let unknown_cast_to = match e {
0 commit comments