@@ -33,9 +33,7 @@ use super::FnCtxt;
33
33
use crate :: errors;
34
34
use crate :: type_error_struct;
35
35
use 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 } ;
39
37
use rustc_hir as hir;
40
38
use rustc_macros:: { TypeFoldable , TypeVisitable } ;
41
39
use rustc_middle:: mir:: Mutability ;
@@ -543,27 +541,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
543
541
CastError :: UnknownExprPtrKind => false ,
544
542
_ => bug ! ( ) ,
545
543
} ;
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 ) )
559
546
} 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
+ } ) ;
567
554
}
568
555
CastError :: ForeignNonExhaustiveAdt => {
569
556
make_invalid_casting_error (
0 commit comments