diff options
| author | Michael Goulet <michael@errs.io> | 2022-11-06 17:14:05 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-11-07 00:30:56 +0000 |
| commit | 152646f23fababe13f9fdd852c9b4efb10f1e150 (patch) | |
| tree | 6e6c3f5b6112065425b650f806f6ca3c1b3dd06a | |
| parent | 7eef946fc0e0eff40e588eab77b09b287accbec3 (diff) | |
| download | rust-152646f23fababe13f9fdd852c9b4efb10f1e150.tar.gz rust-152646f23fababe13f9fdd852c9b4efb10f1e150.zip | |
Don't normalize constants unless they need normalization
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/project.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/query/normalize.rs | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index daee5dd8f02..7f829e46bbb 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -647,7 +647,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { #[instrument(skip(self), level = "debug")] fn fold_const(&mut self, constant: ty::Const<'tcx>) -> ty::Const<'tcx> { let tcx = self.selcx.tcx(); - if tcx.lazy_normalization() { + if tcx.lazy_normalization() || !needs_normalization(&constant, self.param_env.reveal()) { constant } else { let constant = constant.super_fold_with(self); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 715f5be8e2f..a7932b332c9 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -353,6 +353,10 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { &mut self, constant: ty::Const<'tcx>, ) -> Result<ty::Const<'tcx>, Self::Error> { + if !needs_normalization(&constant, self.param_env.reveal()) { + return Ok(constant); + } + let constant = constant.try_super_fold_with(self)?; debug!(?constant, ?self.param_env); Ok(crate::traits::project::with_replaced_escaping_bound_vars( |
