Skip to content

Commit 3834a3a

Browse files
committed
needs_normalization no moreParamEnv::reveal
1 parent c58ec93 commit 3834a3a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub fn normalize_param_env_or_error<'tcx>(
411411
debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates);
412412

413413
let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates), unnormalized_env.reveal());
414-
if !normalize::needs_normalization(&elaborated_env, unnormalized_env.reveal()) {
414+
if !elaborated_env.has_aliases() {
415415
return elaborated_env;
416416
}
417417

compiler/rustc_trait_selection/src/traits/normalize.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Deeply normalize types using the old trait solver.
22
33
use rustc_data_structures::stack::ensure_sufficient_stack;
4-
use rustc_infer::infer::InferOk;
54
use rustc_infer::infer::at::At;
5+
use rustc_infer::infer::{InferCtxt, InferOk};
66
use rustc_infer::traits::{
77
FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine,
88
};
99
use rustc_macros::extension;
10-
use rustc_middle::traits::{ObligationCause, ObligationCauseCode, Reveal};
10+
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
1111
use rustc_middle::ty::{
1212
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt,
1313
TypingMode,
@@ -110,16 +110,19 @@ where
110110
}
111111

112112
pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
113+
infcx: &InferCtxt<'tcx>,
114+
param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
113115
value: &T,
114-
reveal: Reveal,
115116
) -> bool {
116117
let mut flags = ty::TypeFlags::HAS_ALIAS;
117118

118119
// Opaques are treated as rigid with `Reveal::UserFacing`,
119120
// 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 => {}
123126
}
124127

125128
value.has_type_flags(flags)
@@ -155,7 +158,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
155158
"Normalizing {value:?} without wrapping in a `Binder`"
156159
);
157160

158-
if !needs_normalization(&value, self.param_env.reveal()) {
161+
if !needs_normalization(self.selcx.infcx, self.param_env, &value) {
159162
value
160163
} else {
161164
value.fold_with(self)
@@ -179,7 +182,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
179182
}
180183

181184
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) {
183186
return ty;
184187
}
185188

@@ -405,7 +408,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
405408
fn fold_const(&mut self, constant: ty::Const<'tcx>) -> ty::Const<'tcx> {
406409
let tcx = self.selcx.tcx();
407410
if tcx.features().generic_const_exprs()
408-
|| !needs_normalization(&constant, self.param_env.reveal())
411+
|| !needs_normalization(self.selcx.infcx, self.param_env, &constant)
409412
{
410413
constant
411414
} else {
@@ -422,7 +425,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
422425

423426
#[inline]
424427
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) {
426429
p.super_fold_with(self)
427430
} else {
428431
p

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
8989
}
9090
}
9191

92-
if !needs_normalization(&value, self.param_env.reveal()) {
92+
if !needs_normalization(self.infcx, self.param_env, &value) {
9393
return Ok(Normalized { value, obligations: PredicateObligations::new() });
9494
}
9595

@@ -191,7 +191,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
191191

192192
#[instrument(level = "debug", skip(self))]
193193
fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
194-
if !needs_normalization(&ty, self.param_env.reveal()) {
194+
if !needs_normalization(self.infcx, self.param_env, &ty) {
195195
return Ok(ty);
196196
}
197197

@@ -334,7 +334,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
334334
&mut self,
335335
constant: ty::Const<'tcx>,
336336
) -> Result<ty::Const<'tcx>, Self::Error> {
337-
if !needs_normalization(&constant, self.param_env.reveal()) {
337+
if !needs_normalization(self.infcx, self.param_env, &constant) {
338338
return Ok(constant);
339339
}
340340

@@ -353,7 +353,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
353353
&mut self,
354354
p: ty::Predicate<'tcx>,
355355
) -> Result<ty::Predicate<'tcx>, Self::Error> {
356-
if p.allow_normalization() && needs_normalization(&p, self.param_env.reveal()) {
356+
if p.allow_normalization() && needs_normalization(self.infcx, self.param_env, &p) {
357357
p.try_super_fold_with(self)
358358
} else {
359359
Ok(p)

0 commit comments

Comments
 (0)