diff options
| author | bors <bors@rust-lang.org> | 2022-11-08 10:02:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-08 10:02:11 +0000 |
| commit | ddfe1e87f7c85c03773c29180a931447fcd03b65 (patch) | |
| tree | 221fed90bfbb40b39451552125c355308f4b3de3 | |
| parent | 57d3c58ed6e0faf89a62411f96c000ffc9fd3937 (diff) | |
| parent | 152646f23fababe13f9fdd852c9b4efb10f1e150 (diff) | |
| download | rust-ddfe1e87f7c85c03773c29180a931447fcd03b65.tar.gz rust-ddfe1e87f7c85c03773c29180a931447fcd03b65.zip | |
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`
| -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( |
