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