@@ -10,19 +10,19 @@ use rustc_middle::ty::layout::{
1010} ;
1111use rustc_middle:: ty:: {
1212 self , GenericArgsRef , Ty , TyCtxt , TypeFoldable , TypeVisitableExt , TypingEnv , TypingMode ,
13- Variance ,
1413} ;
1514use rustc_middle:: { bug, mir, span_bug} ;
1615use rustc_span:: Span ;
1716use rustc_target:: callconv:: FnAbi ;
17+ use rustc_ty_utils:: compare_types:: mir_assign_valid_types;
1818use tracing:: { debug, trace} ;
1919
2020use super :: {
2121 Frame , FrameInfo , GlobalId , InterpErrorInfo , InterpErrorKind , InterpResult , MPlaceTy , Machine ,
2222 MemPlaceMeta , Memory , OpTy , Place , PlaceTy , PointerArithmetic , Projectable , Provenance ,
2323 err_inval, interp_ok, throw_inval, throw_ub, throw_ub_format,
2424} ;
25- use crate :: { enter_trace_span, util } ;
25+ use crate :: enter_trace_span;
2626
2727pub struct InterpCx < ' tcx , M : Machine < ' tcx > > {
2828 /// Stores the `Machine` instance.
@@ -164,37 +164,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
164164 }
165165}
166166
167- /// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
168- /// This test should be symmetric, as it is primarily about layout compatibility.
169- pub ( super ) fn mir_assign_valid_types < ' tcx > (
170- tcx : TyCtxt < ' tcx > ,
171- typing_env : TypingEnv < ' tcx > ,
172- src : TyAndLayout < ' tcx > ,
173- dest : TyAndLayout < ' tcx > ,
174- ) -> bool {
175- // We relate types invariantly because after borrowck subtyping should be fully explicit via
176- // `Subtype` projections.
177- if util:: relate_types ( tcx, typing_env, Variance :: Invariant , src. ty , dest. ty ) {
178- // Make sure the layout is equal, too -- just to be safe. Miri really
179- // needs layout equality. For performance reason we skip this check when
180- // the types are equal. Equal types *can* have different layouts when
181- // enum downcast is involved (as enum variants carry the type of the
182- // enum), but those should never occur in assignments.
183- if cfg ! ( debug_assertions) || src. ty != dest. ty {
184- assert_eq ! (
185- src. layout,
186- dest. layout,
187- "{src} and {dest} are subtypes of each other but have different layout" ,
188- src = src. ty,
189- dest = dest. ty,
190- ) ;
191- }
192- true
193- } else {
194- false
195- }
196- }
197-
198167/// Use the already known layout if given (but sanity check in debug mode),
199168/// or compute the layout.
200169#[ cfg_attr( not( debug_assertions) , inline( always) ) ]
0 commit comments