@@ -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 ;
@@ -540,27 +538,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
540
538
CastError :: UnknownExprPtrKind => false ,
541
539
_ => bug ! ( ) ,
542
540
} ;
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 ) )
556
543
} 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
+ } ) ;
564
551
}
565
552
CastError :: ForeignNonExhaustiveAdt => {
566
553
make_invalid_casting_error (
0 commit comments