diff options
| author | jackh726 <jack.huey@umassmed.edu> | 2021-07-16 16:23:42 -0400 |
|---|---|---|
| committer | jackh726 <jack.huey@umassmed.edu> | 2021-07-17 16:09:22 -0400 |
| commit | fa839b1194a401c77a5fadba0a2b351870ea4683 (patch) | |
| tree | a05c0a570e739c344cec71cb7a7f01282b27861d | |
| parent | d954a8ee8e76fc69ddc6a3e785a6e986a2e08e52 (diff) | |
| download | rust-fa839b1194a401c77a5fadba0a2b351870ea4683.tar.gz rust-fa839b1194a401c77a5fadba0a2b351870ea4683.zip | |
Add needs_normalization
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/project.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/query/normalize.rs | 5 |
2 files changed, 21 insertions, 4 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index f342042bd11..d1ab9fa025e 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -293,6 +293,18 @@ where result } +pub(crate) fn needs_normalization<'tcx, T: TypeFoldable<'tcx>>(value: &T, reveal: Reveal) -> bool { + match reveal { + Reveal::UserFacing => value + .has_type_flags(ty::TypeFlags::HAS_TY_PROJECTION | ty::TypeFlags::HAS_CT_PROJECTION), + Reveal::All => value.has_type_flags( + ty::TypeFlags::HAS_TY_PROJECTION + | ty::TypeFlags::HAS_TY_OPAQUE + | ty::TypeFlags::HAS_CT_PROJECTION, + ), + } +} + struct AssocTypeNormalizer<'a, 'b, 'tcx> { selcx: &'a mut SelectionContext<'b, 'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -323,7 +335,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { value ); - if !value.has_projections() { value } else { value.fold_with(self) } + if !needs_normalization(&value, self.param_env.reveal()) { + value + } else { + value.fold_with(self) + } } } @@ -343,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if !ty.has_projections() { + if !needs_normalization(&ty, self.param_env.reveal()) { return ty; } // We don't want to normalize associated types that occur inside of region diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index b13b1a6264c..d65a378b1ed 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -6,6 +6,7 @@ use crate::infer::at::At; use crate::infer::canonical::OriginalQueryValues; use crate::infer::{InferCtxt, InferOk}; use crate::traits::error_reporting::InferCtxtExt; +use crate::traits::project::needs_normalization; use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; use rustc_data_structures::sso::SsoHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -49,7 +50,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { value, self.param_env, ); - if !value.has_projections() { + if !needs_normalization(&value, self.param_env.reveal()) { return Ok(Normalized { value, obligations: vec![] }); } @@ -112,7 +113,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { #[instrument(level = "debug", skip(self))] fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if !ty.has_projections() { + if !needs_normalization(&ty, self.param_env.reveal()) { return ty; } |
