@@ -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 ;
@@ -543,27 +541,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
543541 CastError :: UnknownExprPtrKind => false ,
544542 _ => bug ! ( ) ,
545543 } ;
546- let mut err = struct_span_err ! (
547- fcx. tcx. sess,
548- if unknown_cast_to { self . cast_span } else { self . span } ,
549- E0641 ,
550- "cannot cast {} a pointer of an unknown kind" ,
551- if unknown_cast_to { "to" } else { "from" }
552- ) ;
553- if unknown_cast_to {
554- err. span_label ( self . cast_span , "needs more type information" ) ;
555- err. note (
556- "the type information given here is insufficient to check whether \
557- the pointer cast is valid",
558- ) ;
544+ let ( span, sub) = if unknown_cast_to {
545+ ( self . cast_span , errors:: CastUnknownPointerSub :: To ( self . cast_span ) )
559546 } else {
560- err . span_label (
561- self . span ,
562- "the type information given here is insufficient to check whether \
563- the pointer cast is valid" ,
564- ) ;
565- }
566- err . emit ( ) ;
547+ ( self . cast_span , errors :: CastUnknownPointerSub :: From ( self . span ) )
548+ } ;
549+ fcx . tcx . sess . emit_err ( errors :: CastUnknownPointer {
550+ span ,
551+ to : unknown_cast_to ,
552+ sub ,
553+ } ) ;
567554 }
568555 CastError :: ForeignNonExhaustiveAdt => {
569556 make_invalid_casting_error (
0 commit comments