@@ -16,6 +16,8 @@ use rustc_target::spec::abi::Abi;
1616
1717use crate :: util:: is_within_packed;
1818
19+ use crate :: util:: is_subtype;
20+
1921#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
2022enum EdgeKind {
2123 Unwind ,
@@ -602,35 +604,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
602604 return true ;
603605 }
604606
605- crate :: util:: is_subtype ( self . tcx , self . param_env , src, dest)
607+ return crate :: util:: is_subtype ( self . tcx , self . param_env , src, dest) ;
606608 }
607609}
608610
609611impl < ' a , ' tcx > Visitor < ' tcx > for TypeChecker < ' a , ' tcx > {
610612 fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
611- match operand {
612- Operand :: Copy ( place) | Operand :: Move ( place) => {
613- if let Some ( stmt) = self . body . stmt_at ( location) . left ( ) {
614- match & stmt. kind {
615- StatementKind :: Assign ( box ( lval, rvalue) ) => {
616- let place_ty = place. ty ( & self . body . local_decls , self . tcx ) . ty ;
617- let lval_ty = lval. ty ( & self . body . local_decls , self . tcx ) . ty ;
618-
619- if !place. is_subtype ( )
620- && place_ty != lval_ty
621- && rvalue. ty ( & self . body . local_decls , self . tcx ) != lval_ty
622- && ( rvalue. ty ( & self . body . local_decls , self . tcx ) . is_closure ( )
623- != lval_ty. is_closure ( ) )
624- {
625- self . fail ( location, format ! ( "Subtyping is not allowed between types {place_ty:#?} and {lval_ty:#?}" ) )
626- }
627- }
628- _ => ( ) ,
629- }
630- }
631- }
632- _ => ( ) ,
633- }
634613 // This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
635614 if self . tcx . sess . opts . unstable_opts . validate_mir
636615 && self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial )
@@ -776,6 +755,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
776755 }
777756 }
778757 }
758+ ProjectionElem :: Subtype ( ty) => {
759+ if !is_subtype (
760+ self . tcx ,
761+ self . param_env ,
762+ ty,
763+ place_ref. ty ( & self . body . local_decls , self . tcx ) . ty ,
764+ ) {
765+ self . fail (
766+ location,
767+ format ! (
768+ "Failed subtyping {ty:#?} and {:#?}" ,
769+ place_ref. ty( & self . body. local_decls, self . tcx) . ty
770+ ) ,
771+ )
772+ }
773+ }
779774 _ => { }
780775 }
781776 self . super_projection_elem ( place_ref, elem, context, location) ;
0 commit comments