@@ -32,6 +32,7 @@ use rustc_ast::util::parser::ExprPrecedence;
32
32
use rustc_data_structures:: fx:: FxHashSet ;
33
33
use rustc_errors:: codes:: * ;
34
34
use rustc_errors:: { Applicability , Diag , ErrorGuaranteed } ;
35
+ use rustc_hir:: def_id:: DefId ;
35
36
use rustc_hir:: { self as hir, ExprKind } ;
36
37
use rustc_infer:: infer:: DefineOpaqueTypes ;
37
38
use rustc_macros:: { TypeFoldable , TypeVisitable } ;
@@ -155,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
155
156
}
156
157
}
157
158
158
- #[ derive( Copy , Clone , Debug ) ]
159
+ #[ derive( Debug ) ]
159
160
enum CastError < ' tcx > {
160
161
ErrorGuaranteed ( ErrorGuaranteed ) ,
161
162
@@ -182,6 +183,7 @@ enum CastError<'tcx> {
182
183
/// when we're typechecking a type parameter with a ?Sized bound.
183
184
IntToWideCast ( Option < & ' static str > ) ,
184
185
ForeignNonExhaustiveAdt ,
186
+ PtrPtrAddingAutoTrait ( Vec < DefId > ) ,
185
187
}
186
188
187
189
impl From < ErrorGuaranteed > for CastError < ' _ > {
@@ -596,6 +598,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
596
598
. with_note ( "cannot cast an enum with a non-exhaustive variant when it's defined in another crate" )
597
599
. emit ( ) ;
598
600
}
601
+ CastError :: PtrPtrAddingAutoTrait ( added) => {
602
+ fcx. dcx ( ) . emit_err ( errors:: PtrCastAddAutoToObject {
603
+ span : self . span ,
604
+ traits_len : added. len ( ) ,
605
+ traits : {
606
+ let mut traits: Vec < _ > = added
607
+ . into_iter ( )
608
+ . map ( |trait_did| fcx. tcx . def_path_str ( trait_did) )
609
+ . collect ( ) ;
610
+
611
+ traits. sort ( ) ;
612
+ traits. into ( )
613
+ } ,
614
+ } ) ;
615
+ }
599
616
}
600
617
}
601
618
@@ -940,19 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
940
957
. collect :: < Vec < _ > > ( ) ;
941
958
942
959
if !added. is_empty ( ) {
943
- tcx. dcx ( ) . emit_err ( errors:: PtrCastAddAutoToObject {
944
- span : self . span ,
945
- traits_len : added. len ( ) ,
946
- traits : {
947
- let mut traits: Vec < _ > = added
948
- . into_iter ( )
949
- . map ( |trait_did| tcx. def_path_str ( trait_did) )
950
- . collect ( ) ;
951
-
952
- traits. sort ( ) ;
953
- traits. into ( )
954
- } ,
955
- } ) ;
960
+ return Err ( CastError :: PtrPtrAddingAutoTrait ( added) ) ;
956
961
}
957
962
958
963
Ok ( CastKind :: PtrPtrCast )
0 commit comments