Skip to content

Commit ddfe1e8

Browse files
committed
Auto merge of #104063 - compiler-errors:ct-norm-unless, r=jackh726
Don't normalize constants unless they need normalization Maybe makes normalization a bit faster when we have many constants in a type r? `@ghost`
2 parents 57d3c58 + 152646f commit ddfe1e8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
647647
#[instrument(skip(self), level = "debug")]
648648
fn fold_const(&mut self, constant: ty::Const<'tcx>) -> ty::Const<'tcx> {
649649
let tcx = self.selcx.tcx();
650-
if tcx.lazy_normalization() {
650+
if tcx.lazy_normalization() || !needs_normalization(&constant, self.param_env.reveal()) {
651651
constant
652652
} else {
653653
let constant = constant.super_fold_with(self);

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

+4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
353353
&mut self,
354354
constant: ty::Const<'tcx>,
355355
) -> Result<ty::Const<'tcx>, Self::Error> {
356+
if !needs_normalization(&constant, self.param_env.reveal()) {
357+
return Ok(constant);
358+
}
359+
356360
let constant = constant.try_super_fold_with(self)?;
357361
debug!(?constant, ?self.param_env);
358362
Ok(crate::traits::project::with_replaced_escaping_bound_vars(

0 commit comments

Comments
 (0)