Skip to content

Commit fa839b1

Browse files
committed
Add needs_normalization
1 parent d954a8e commit fa839b1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ where
293293
result
294294
}
295295

296+
pub(crate) fn needs_normalization<'tcx, T: TypeFoldable<'tcx>>(value: &T, reveal: Reveal) -> bool {
297+
match reveal {
298+
Reveal::UserFacing => value
299+
.has_type_flags(ty::TypeFlags::HAS_TY_PROJECTION | ty::TypeFlags::HAS_CT_PROJECTION),
300+
Reveal::All => value.has_type_flags(
301+
ty::TypeFlags::HAS_TY_PROJECTION
302+
| ty::TypeFlags::HAS_TY_OPAQUE
303+
| ty::TypeFlags::HAS_CT_PROJECTION,
304+
),
305+
}
306+
}
307+
296308
struct AssocTypeNormalizer<'a, 'b, 'tcx> {
297309
selcx: &'a mut SelectionContext<'b, 'tcx>,
298310
param_env: ty::ParamEnv<'tcx>,
@@ -323,7 +335,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
323335
value
324336
);
325337

326-
if !value.has_projections() { value } else { value.fold_with(self) }
338+
if !needs_normalization(&value, self.param_env.reveal()) {
339+
value
340+
} else {
341+
value.fold_with(self)
342+
}
327343
}
328344
}
329345

@@ -343,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
343359
}
344360

345361
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
346-
if !ty.has_projections() {
362+
if !needs_normalization(&ty, self.param_env.reveal()) {
347363
return ty;
348364
}
349365
// We don't want to normalize associated types that occur inside of region

Diff for: compiler/rustc_trait_selection/src/traits/query/normalize.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::infer::at::At;
66
use crate::infer::canonical::OriginalQueryValues;
77
use crate::infer::{InferCtxt, InferOk};
88
use crate::traits::error_reporting::InferCtxtExt;
9+
use crate::traits::project::needs_normalization;
910
use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
1011
use rustc_data_structures::sso::SsoHashMap;
1112
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -49,7 +50,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
4950
value,
5051
self.param_env,
5152
);
52-
if !value.has_projections() {
53+
if !needs_normalization(&value, self.param_env.reveal()) {
5354
return Ok(Normalized { value, obligations: vec![] });
5455
}
5556

@@ -112,7 +113,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
112113

113114
#[instrument(level = "debug", skip(self))]
114115
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
115-
if !ty.has_projections() {
116+
if !needs_normalization(&ty, self.param_env.reveal()) {
116117
return ty;
117118
}
118119

0 commit comments

Comments
 (0)