1
1
//! Deeply normalize types using the old trait solver.
2
2
3
3
use rustc_data_structures::stack::ensure_sufficient_stack;
4
- use rustc_infer::infer::InferOk;
5
4
use rustc_infer::infer::at::At;
5
+ use rustc_infer::infer::{InferCtxt, InferOk};
6
6
use rustc_infer::traits::{
7
7
FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine,
8
8
};
9
9
use rustc_macros::extension;
10
- use rustc_middle::traits::{ObligationCause, ObligationCauseCode, Reveal };
10
+ use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
11
11
use rustc_middle::ty::{
12
12
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt,
13
13
TypingMode,
@@ -110,16 +110,19 @@ where
110
110
}
111
111
112
112
pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
113
+ infcx: &InferCtxt<'tcx>,
114
+ param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
113
115
value: &T,
114
- reveal: Reveal,
115
116
) -> bool {
116
117
let mut flags = ty::TypeFlags::HAS_ALIAS;
117
118
118
119
// Opaques are treated as rigid with `Reveal::UserFacing`,
119
120
// so we can ignore those.
120
- match reveal {
121
- Reveal::UserFacing => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE),
122
- Reveal::All => {}
121
+ match infcx.typing_mode(param_env_for_debug_assertion) {
122
+ TypingMode::Coherence | TypingMode::Analysis { defining_opaque_types: _ } => {
123
+ flags.remove(ty::TypeFlags::HAS_TY_OPAQUE)
124
+ }
125
+ TypingMode::PostAnalysis => {}
123
126
}
124
127
125
128
value.has_type_flags(flags)
@@ -155,7 +158,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
155
158
"Normalizing {value:?} without wrapping in a `Binder`"
156
159
);
157
160
158
- if !needs_normalization(&value , self.param_env.reveal() ) {
161
+ if !needs_normalization(self.selcx.infcx , self.param_env, &value ) {
159
162
value
160
163
} else {
161
164
value.fold_with(self)
@@ -179,7 +182,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
179
182
}
180
183
181
184
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
182
- if !needs_normalization(&ty , self.param_env.reveal() ) {
185
+ if !needs_normalization(self.selcx.infcx , self.param_env, &ty ) {
183
186
return ty;
184
187
}
185
188
@@ -405,7 +408,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
405
408
fn fold_const(&mut self, constant: ty::Const<'tcx>) -> ty::Const<'tcx> {
406
409
let tcx = self.selcx.tcx();
407
410
if tcx.features().generic_const_exprs()
408
- || !needs_normalization(&constant , self.param_env.reveal() )
411
+ || !needs_normalization(self.selcx.infcx , self.param_env, &constant )
409
412
{
410
413
constant
411
414
} else {
@@ -422,7 +425,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
422
425
423
426
#[inline]
424
427
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
425
- if p.allow_normalization() && needs_normalization(&p , self.param_env.reveal() ) {
428
+ if p.allow_normalization() && needs_normalization(self.selcx.infcx , self.param_env, &p ) {
426
429
p.super_fold_with(self)
427
430
} else {
428
431
p
0 commit comments