@@ -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 ;
@@ -544,27 +542,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
544
542
CastError :: UnknownExprPtrKind => false ,
545
543
_ => bug ! ( ) ,
546
544
} ;
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 ) )
560
547
} 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
+ } ) ;
568
555
}
569
556
CastError :: ForeignNonExhaustiveAdt => {
570
557
make_invalid_casting_error (
0 commit comments