@@ -33,9 +33,7 @@ use super::FnCtxt;
3333use crate :: errors;
3434use crate :: type_error_struct;
3535use hir:: ExprKind ;
36- use rustc_errors:: {
37- struct_span_err, Applicability , DelayDm , Diagnostic , DiagnosticBuilder , ErrorGuaranteed ,
38- } ;
36+ use rustc_errors:: { Applicability , DelayDm , Diagnostic , DiagnosticBuilder , ErrorGuaranteed } ;
3937use rustc_hir as hir;
4038use rustc_macros:: { TypeFoldable , TypeVisitable } ;
4139use rustc_middle:: mir:: Mutability ;
@@ -544,27 +542,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
544542 CastError :: UnknownExprPtrKind => false ,
545543 _ => bug ! ( ) ,
546544 } ;
547- let mut err = struct_span_err ! (
548- fcx. tcx. sess,
549- if unknown_cast_to { self . cast_span } else { self . span } ,
550- E0641 ,
551- "cannot cast {} a pointer of an unknown kind" ,
552- if unknown_cast_to { "to" } else { "from" }
553- ) ;
554- if unknown_cast_to {
555- err. span_label ( self . cast_span , "needs more type information" ) ;
556- err. note (
557- "the type information given here is insufficient to check whether \
558- the pointer cast is valid",
559- ) ;
545+ let ( span, sub) = if unknown_cast_to {
546+ ( self . cast_span , errors:: CastUnknownPointerSub :: To ( self . cast_span ) )
560547 } else {
561- err . span_label (
562- self . span ,
563- "the type information given here is insufficient to check whether \
564- the pointer cast is valid" ,
565- ) ;
566- }
567- err . emit ( ) ;
548+ ( self . cast_span , errors :: CastUnknownPointerSub :: From ( self . span ) )
549+ } ;
550+ fcx . tcx . sess . emit_err ( errors :: CastUnknownPointer {
551+ span ,
552+ to : unknown_cast_to ,
553+ sub ,
554+ } ) ;
568555 }
569556 CastError :: ForeignNonExhaustiveAdt => {
570557 make_invalid_casting_error (
0 commit comments