@@ -35,13 +35,12 @@ use crate::type_error_struct;
3535use hir:: def_id:: LOCAL_CRATE ;
3636use rustc_errors:: { struct_span_err, Applicability , DelayDm , DiagnosticBuilder , ErrorGuaranteed } ;
3737use rustc_hir as hir;
38- use rustc_infer:: traits:: { Obligation , ObligationCause , ObligationCauseCode } ;
3938use rustc_middle:: mir:: Mutability ;
4039use rustc_middle:: ty:: adjustment:: AllowTwoPhase ;
4140use rustc_middle:: ty:: cast:: { CastKind , CastTy } ;
4241use rustc_middle:: ty:: error:: TypeError ;
4342use rustc_middle:: ty:: subst:: SubstsRef ;
44- use rustc_middle:: ty:: { self , Binder , Ty , TypeAndMut , TypeVisitable , VariantDef } ;
43+ use rustc_middle:: ty:: { self , Ty , TypeAndMut , TypeVisitable , VariantDef } ;
4544use rustc_session:: lint;
4645use rustc_session:: Session ;
4746use rustc_span:: symbol:: sym;
@@ -218,58 +217,10 @@ pub fn check_cast<'tcx>(
218217 cast_span : Span ,
219218 span : Span ,
220219) -> CastCheckResult < ' tcx > {
221- if cast_ty. is_dyn_star ( ) {
222- check_dyn_star_cast ( fcx, expr, expr_ty, cast_ty)
223- } else {
224- match CastCheck :: new ( fcx, expr, expr_ty, cast_ty, cast_span, span) {
225- Ok ( check) => CastCheckResult :: Deferred ( check) ,
226- Err ( e) => CastCheckResult :: Err ( e) ,
227- }
228- }
229- }
230-
231- fn check_dyn_star_cast < ' tcx > (
232- fcx : & FnCtxt < ' _ , ' tcx > ,
233- expr : & ' tcx hir:: Expr < ' tcx > ,
234- expr_ty : Ty < ' tcx > ,
235- cast_ty : Ty < ' tcx > ,
236- ) -> CastCheckResult < ' tcx > {
237- // Find the bounds in the dyn*. For eaxmple, if we have
238- //
239- // let x = 22_usize as dyn* (Clone + Debug + 'static)
240- //
241- // this would return `existential_predicates = [?Self: Clone, ?Self: Debug]` and `region = 'static`.
242- let ( existential_predicates, region) = match cast_ty. kind ( ) {
243- ty:: Dynamic ( predicates, region, ty:: DynStar ) => ( predicates, region) ,
244- _ => panic ! ( "Invalid dyn* cast_ty" ) ,
245- } ;
246-
247- let cause = ObligationCause :: new (
248- expr. span ,
249- fcx. body_id ,
250- // FIXME(dyn-star): Use a better obligation cause code
251- ObligationCauseCode :: MiscObligation ,
252- ) ;
253-
254- // For each existential predicate (e.g., `?Self: Clone`) substitute
255- // the type of the expression (e.g., `usize` in our example above)
256- // and then require that the resulting predicate (e.g., `usize: Clone`)
257- // holds (it does).
258- for existential_predicate in existential_predicates. iter ( ) {
259- let predicate = existential_predicate. with_self_ty ( fcx. tcx , expr_ty) ;
260- fcx. register_predicate ( Obligation :: new ( cause. clone ( ) , fcx. param_env , predicate) ) ;
220+ match CastCheck :: new ( fcx, expr, expr_ty, cast_ty, cast_span, span) {
221+ Ok ( check) => CastCheckResult :: Deferred ( check) ,
222+ Err ( e) => CastCheckResult :: Err ( e) ,
261223 }
262-
263- // Enforce the region bound `'static` (e.g., `usize: 'static`, in our example).
264- fcx. register_predicate ( Obligation :: new (
265- cause,
266- fcx. param_env ,
267- fcx. tcx . mk_predicate ( Binder :: dummy ( ty:: PredicateKind :: TypeOutlives (
268- ty:: OutlivesPredicate ( expr_ty, * region) ,
269- ) ) ) ,
270- ) ) ;
271-
272- CastCheckResult :: Ok
273224}
274225
275226impl < ' a , ' tcx > CastCheck < ' tcx > {
@@ -934,11 +885,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
934885
935886 ( Int ( _) | Float , Int ( _) | Float ) => Ok ( CastKind :: NumericCast ) ,
936887
937- // FIXME(dyn-star): this needs more conditions...
938- ( _, DynStar ) => Ok ( CastKind :: DynStarCast ) ,
939-
940- // FIXME(dyn-star): do we want to allow dyn* upcasting or other casts?
941- ( DynStar , _) => Err ( CastError :: IllegalCast ) ,
888+ ( _, DynStar ) | ( DynStar , _) => bug ! ( "should be handled by `try_coerce`" ) ,
942889 }
943890 }
944891
0 commit comments