@@ -33,12 +33,12 @@ use rustc_errors::codes::*;
3333use rustc_errors:: { Applicability , Diag , ErrorGuaranteed } ;
3434use rustc_hir:: { self as hir, ExprKind } ;
3535use rustc_macros:: { TypeFoldable , TypeVisitable } ;
36- use rustc_middle:: bug;
3736use rustc_middle:: mir:: Mutability ;
3837use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
3938use rustc_middle:: ty:: cast:: { CastKind , CastTy } ;
4039use rustc_middle:: ty:: error:: TypeError ;
4140use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeAndMut , TypeVisitableExt , VariantDef } ;
41+ use rustc_middle:: { bug, span_bug} ;
4242use rustc_session:: lint;
4343use rustc_span:: def_id:: LOCAL_CRATE ;
4444use rustc_span:: symbol:: sym;
@@ -674,6 +674,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
674674 use rustc_middle:: ty:: cast:: CastTy :: * ;
675675 use rustc_middle:: ty:: cast:: IntTy :: * ;
676676
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+
677687 let ( t_from, t_cast) = match ( CastTy :: from_ty ( self . expr_ty ) , CastTy :: from_ty ( self . cast_ty ) )
678688 {
679689 ( Some ( t_from) , Some ( t_cast) ) => ( t_from, t_cast) ,
@@ -780,16 +790,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
780790 ( Int ( Char ) | Int ( Bool ) , Int ( _) ) => Ok ( CastKind :: PrimIntCast ) ,
781791
782792 ( 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 ) ,
793793 }
794794 }
795795
0 commit comments