@@ -16,6 +16,8 @@ use rustc_target::spec::abi::Abi;
16
16
17
17
use crate :: util:: is_within_packed;
18
18
19
+ use crate :: util:: is_subtype;
20
+
19
21
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
20
22
enum EdgeKind {
21
23
Unwind ,
@@ -602,35 +604,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
602
604
return true ;
603
605
}
604
606
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) ;
606
608
}
607
609
}
608
610
609
611
impl < ' a , ' tcx > Visitor < ' tcx > for TypeChecker < ' a , ' tcx > {
610
612
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
- }
634
613
// This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
635
614
if self . tcx . sess . opts . unstable_opts . validate_mir
636
615
&& self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial )
@@ -776,6 +755,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
776
755
}
777
756
}
778
757
}
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
+ }
779
774
_ => { }
780
775
}
781
776
self . super_projection_elem ( place_ref, elem, context, location) ;
0 commit comments