@@ -3,7 +3,7 @@ use rustc_errors::DiagCtxtHandle;
3
3
use rustc_hir:: def_id:: DefId ;
4
4
use rustc_infer:: infer:: TyCtxtInferExt ;
5
5
use rustc_infer:: infer:: at:: ToTrace ;
6
- use rustc_infer:: traits:: ObligationCause ;
6
+ use rustc_infer:: traits:: { ObligationCause , Reveal } ;
7
7
use rustc_middle:: mir:: interpret:: { ErrorHandled , InvalidMetaKind , ReportedErrorInfo } ;
8
8
use rustc_middle:: query:: TyCtxtAt ;
9
9
use rustc_middle:: ty:: layout:: {
@@ -116,6 +116,7 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
116
116
/// This test should be symmetric, as it is primarily about layout compatibility.
117
117
pub ( super ) fn mir_assign_valid_types < ' tcx > (
118
118
tcx : TyCtxt < ' tcx > ,
119
+ typing_mode : TypingMode < ' tcx > ,
119
120
param_env : ParamEnv < ' tcx > ,
120
121
src : TyAndLayout < ' tcx > ,
121
122
dest : TyAndLayout < ' tcx > ,
@@ -124,7 +125,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
124
125
// all normal lifetimes are erased, higher-ranked types with their
125
126
// late-bound lifetimes are still around and can lead to type
126
127
// 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 ) {
128
129
// Make sure the layout is equal, too -- just to be safe. Miri really
129
130
// needs layout equality. For performance reason we skip this check when
130
131
// the types are equal. Equal types *can* have different layouts when
@@ -144,6 +145,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
144
145
#[ cfg_attr( not( debug_assertions) , inline( always) ) ]
145
146
pub ( super ) fn from_known_layout < ' tcx > (
146
147
tcx : TyCtxtAt < ' tcx > ,
148
+ typing_mode : TypingMode < ' tcx > ,
147
149
param_env : ParamEnv < ' tcx > ,
148
150
known_layout : Option < TyAndLayout < ' tcx > > ,
149
151
compute : impl FnOnce ( ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > ,
@@ -153,7 +155,13 @@ pub(super) fn from_known_layout<'tcx>(
153
155
Some ( known_layout) => {
154
156
if cfg ! ( debug_assertions) {
155
157
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
+ ) {
157
165
span_bug ! (
158
166
tcx. span,
159
167
"expected type differs from actual type.\n expected: {}\n actual: {}" ,
@@ -203,6 +211,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
203
211
}
204
212
}
205
213
214
+ pub fn typing_mode ( & self ) -> TypingMode < ' tcx > {
215
+ debug_assert_eq ! ( self . param_env. reveal( ) , Reveal :: All ) ;
216
+ TypingMode :: PostAnalysis
217
+ }
218
+
206
219
/// Returns the span of the currently executed statement/terminator.
207
220
/// This is the span typically used for error reporting.
208
221
#[ inline( always) ]
@@ -327,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
327
340
return true ;
328
341
}
329
342
// 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 ( ) ) ;
331
344
let ocx = ObligationCtxt :: new ( & infcx) ;
332
345
let cause = ObligationCause :: dummy_with_span ( self . cur_span ( ) ) ;
333
346
// equate the two trait refs after normalization
0 commit comments