@@ -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;
@@ -678,6 +678,16 @@ impl<'a, 'tcx> CastCheck<'tcx> {
678
678
use rustc_middle:: ty:: cast:: CastTy :: * ;
679
679
use rustc_middle:: ty:: cast:: IntTy :: * ;
680
680
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
+
681
691
let ( t_from, t_cast) = match ( CastTy :: from_ty ( self . expr_ty ) , CastTy :: from_ty ( self . cast_ty ) )
682
692
{
683
693
( Some ( t_from) , Some ( t_cast) ) => ( t_from, t_cast) ,
@@ -784,16 +794,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
784
794
( Int ( Char ) | Int ( Bool ) , Int ( _) ) => Ok ( CastKind :: PrimIntCast ) ,
785
795
786
796
( 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 ) ,
797
797
}
798
798
}
799
799
0 commit comments