@@ -33,12 +33,12 @@ use rustc_errors::codes::*;
33
33
use rustc_errors:: { Applicability , Diag , ErrorGuaranteed } ;
34
34
use rustc_hir:: { self as hir, ExprKind } ;
35
35
use rustc_macros:: { TypeFoldable , TypeVisitable } ;
36
- use rustc_middle:: bug;
37
36
use rustc_middle:: mir:: Mutability ;
38
37
use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
39
38
use rustc_middle:: ty:: cast:: { CastKind , CastTy } ;
40
39
use rustc_middle:: ty:: error:: TypeError ;
41
40
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeAndMut , TypeVisitableExt , VariantDef } ;
41
+ use rustc_middle:: { bug, span_bug} ;
42
42
use rustc_session:: lint;
43
43
use rustc_span:: def_id:: LOCAL_CRATE ;
44
44
use rustc_span:: symbol:: sym;
@@ -674,6 +674,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
674
674
use rustc_middle:: ty:: cast:: CastTy :: * ;
675
675
use rustc_middle:: ty:: cast:: IntTy :: * ;
676
676
677
+ if self . cast_ty . is_dyn_star ( ) {
678
+ if fcx. tcx . features ( ) . dyn_star {
679
+ span_bug ! ( self . span, "should be handled by `coerce`" ) ;
680
+ } else {
681
+ // Report "casting is invalid" rather than "non-primitive cast"
682
+ // if the feature is not enabled.
683
+ return Err ( CastError :: IllegalCast ) ;
684
+ }
685
+ }
686
+
677
687
let ( t_from, t_cast) = match ( CastTy :: from_ty ( self . expr_ty ) , CastTy :: from_ty ( self . cast_ty ) )
678
688
{
679
689
( Some ( t_from) , Some ( t_cast) ) => ( t_from, t_cast) ,
@@ -780,16 +790,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
780
790
( Int ( Char ) | Int ( Bool ) , Int ( _) ) => Ok ( CastKind :: PrimIntCast ) ,
781
791
782
792
( Int ( _) | Float , Int ( _) | Float ) => Ok ( CastKind :: NumericCast ) ,
783
-
784
- ( _, DynStar ) => {
785
- if fcx. tcx . features ( ) . dyn_star {
786
- bug ! ( "should be handled by `coerce`" )
787
- } else {
788
- Err ( CastError :: IllegalCast )
789
- }
790
- }
791
-
792
- ( DynStar , _) => Err ( CastError :: IllegalCast ) ,
793
793
}
794
794
}
795
795
0 commit comments