@@ -3,7 +3,7 @@ use rustc_errors::DiagCtxtHandle;
33use rustc_hir:: def_id:: DefId ;
44use rustc_infer:: infer:: TyCtxtInferExt ;
55use rustc_infer:: infer:: at:: ToTrace ;
6- use rustc_infer:: traits:: ObligationCause ;
6+ use rustc_infer:: traits:: { ObligationCause , Reveal } ;
77use rustc_middle:: mir:: interpret:: { ErrorHandled , InvalidMetaKind , ReportedErrorInfo } ;
88use rustc_middle:: query:: TyCtxtAt ;
99use rustc_middle:: ty:: layout:: {
@@ -116,6 +116,7 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
116116/// This test should be symmetric, as it is primarily about layout compatibility.
117117pub ( super ) fn mir_assign_valid_types < ' tcx > (
118118 tcx : TyCtxt < ' tcx > ,
119+ typing_mode : TypingMode < ' tcx > ,
119120 param_env : ParamEnv < ' tcx > ,
120121 src : TyAndLayout < ' tcx > ,
121122 dest : TyAndLayout < ' tcx > ,
@@ -124,7 +125,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
124125 // all normal lifetimes are erased, higher-ranked types with their
125126 // late-bound lifetimes are still around and can lead to type
126127 // differences.
127- if util:: relate_types ( tcx, param_env, Variance :: Covariant , src. ty , dest. ty ) {
128+ if util:: relate_types ( tcx, typing_mode , param_env, Variance :: Covariant , src. ty , dest. ty ) {
128129 // Make sure the layout is equal, too -- just to be safe. Miri really
129130 // needs layout equality. For performance reason we skip this check when
130131 // the types are equal. Equal types *can* have different layouts when
@@ -144,6 +145,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
144145#[ cfg_attr( not( debug_assertions) , inline( always) ) ]
145146pub ( super ) fn from_known_layout < ' tcx > (
146147 tcx : TyCtxtAt < ' tcx > ,
148+ typing_mode : TypingMode < ' tcx > ,
147149 param_env : ParamEnv < ' tcx > ,
148150 known_layout : Option < TyAndLayout < ' tcx > > ,
149151 compute : impl FnOnce ( ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > ,
@@ -153,7 +155,13 @@ pub(super) fn from_known_layout<'tcx>(
153155 Some ( known_layout) => {
154156 if cfg ! ( debug_assertions) {
155157 let check_layout = compute ( ) ?;
156- if !mir_assign_valid_types ( tcx. tcx , param_env, check_layout, known_layout) {
158+ if !mir_assign_valid_types (
159+ tcx. tcx ,
160+ typing_mode,
161+ param_env,
162+ check_layout,
163+ known_layout,
164+ ) {
157165 span_bug ! (
158166 tcx. span,
159167 "expected type differs from actual type.\n expected: {}\n actual: {}" ,
@@ -203,6 +211,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
203211 }
204212 }
205213
214+ pub fn typing_mode ( & self ) -> TypingMode < ' tcx > {
215+ debug_assert_eq ! ( self . param_env. reveal( ) , Reveal :: All ) ;
216+ TypingMode :: PostAnalysis
217+ }
218+
206219 /// Returns the span of the currently executed statement/terminator.
207220 /// This is the span typically used for error reporting.
208221 #[ inline( always) ]
@@ -327,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
327340 return true ;
328341 }
329342 // Slow path: spin up an inference context to check if these traits are sufficiently equal.
330- let infcx = self . tcx . infer_ctxt ( ) . build ( TypingMode :: from_param_env ( self . param_env ) ) ;
343+ let infcx = self . tcx . infer_ctxt ( ) . build ( self . typing_mode ( ) ) ;
331344 let ocx = ObligationCtxt :: new ( & infcx) ;
332345 let cause = ObligationCause :: dummy_with_span ( self . cur_span ( ) ) ;
333346 // equate the two trait refs after normalization
0 commit comments