@@ -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;
@@ -678,6 +678,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
678678 use rustc_middle:: ty:: cast:: CastTy :: * ;
679679 use rustc_middle:: ty:: cast:: IntTy :: * ;
680680
681+ if self . cast_ty . is_dyn_star ( ) {
682+ if fcx. tcx . features ( ) . dyn_star {
683+ span_bug ! ( self . span, "should be handled by `coerce`" ) ;
684+ } else {
685+ // Report "casting is invalid" rather than "non-primitive cast"
686+ // if the feature is not enabled.
687+ return Err ( CastError :: IllegalCast ) ;
688+ }
689+ }
690+
681691 let ( t_from, t_cast) = match ( CastTy :: from_ty ( self . expr_ty ) , CastTy :: from_ty ( self . cast_ty ) )
682692 {
683693 ( Some ( t_from) , Some ( t_cast) ) => ( t_from, t_cast) ,
@@ -784,16 +794,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
784794 ( Int ( Char ) | Int ( Bool ) , Int ( _) ) => Ok ( CastKind :: PrimIntCast ) ,
785795
786796 ( Int ( _) | Float , Int ( _) | Float ) => Ok ( CastKind :: NumericCast ) ,
787-
788- ( _, DynStar ) => {
789- if fcx. tcx . features ( ) . dyn_star {
790- bug ! ( "should be handled by `coerce`" )
791- } else {
792- Err ( CastError :: IllegalCast )
793- }
794- }
795-
796- ( DynStar , _) => Err ( CastError :: IllegalCast ) ,
797797 }
798798 }
799799
0 commit comments