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