@@ -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,38 +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- pub ( super ) fn mir_assign_valid_types < ' tcx > (
169- tcx : TyCtxt < ' tcx > ,
170- typing_env : TypingEnv < ' tcx > ,
171- src : TyAndLayout < ' tcx > ,
172- dest : TyAndLayout < ' tcx > ,
173- ) -> bool {
174- // We *could* check `Invariant` here since all subtyping must be explicit post-borrowck.
175- // However, this check is also used by the interpreter to figure out if a transmute can be
176- // turned into a regular assignment (which has a more efficient codepath), so we want the check
177- // to consider as many assignments as possible to be valid. Therefore we are happy to accept
178- // one-way subtyping.
179- if util:: relate_types ( tcx, typing_env, Variance :: Covariant , src. ty , dest. ty ) {
180- // Make sure the layout is equal, too -- just to be safe. Miri really needs layout equality.
181- // For performance reason we skip this check when the types are equal. Equal types *can*
182- // have different layouts when enum downcast is involved (as enum variants carry the type of
183- // the enum), but those should never occur in assignments.
184- if cfg ! ( debug_assertions) || src. ty != dest. ty {
185- assert_eq ! (
186- src. layout,
187- dest. layout,
188- "{src} is a subtype of {dest} but they have different layout" ,
189- src = src. ty,
190- dest = dest. ty,
191- ) ;
192- }
193- true
194- } else {
195- false
196- }
197- }
198-
199167/// Use the already known layout if given (but sanity check in debug mode),
200168/// or compute the layout.
201169#[ cfg_attr( not( debug_assertions) , inline( always) ) ]
0 commit comments