diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 21ea2c70fbb3..8ae23a92628f 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -207,7 +207,7 @@ pub(super) fn deeply_normalize(&mut self, value: T, location: impl NormalizeL #[instrument(skip(self), level = "debug")] pub(super) fn normalize_with_category( &mut self, - value: T, + value: Unnormalized<'tcx, T>, location: impl NormalizeLocation, category: ConstraintCategory<'tcx>, ) -> T diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index 1f06b1c94237..11b00073fa28 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -1,7 +1,7 @@ use rustc_hir::limit::Limit; use rustc_infer::infer::InferCtxt; use rustc_infer::traits::PredicateObligations; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, Unnormalized}; use rustc_span::def_id::{LOCAL_CRATE, LocalDefId}; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::traits::ObligationCtxt; @@ -187,7 +187,7 @@ fn overloaded_deref_ty(&mut self, ty: Ty<'tcx>) -> Option> { #[instrument(level = "debug", skip(self), ret)] pub fn structurally_normalize_ty( &self, - ty: Ty<'tcx>, + ty: Unnormalized<'tcx, Ty<'tcx>>, ) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> { let ocx = ObligationCtxt::new(self.infcx); let Ok(normalized_ty) = ocx.structurally_normalize_ty( diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 4ab69f7a7b09..a48f6782b041 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -66,7 +66,12 @@ fn tcx(&self) -> TyCtxt<'tcx> { // Convenience function to normalize during wfcheck. This performs // `ObligationCtxt::normalize`, but provides a nice `ObligationCauseCode`. - fn normalize(&self, span: Span, loc: Option, value: T) -> T + fn normalize( + &self, + span: Span, + loc: Option, + value: Unnormalized<'tcx, T>, + ) -> T where T: TypeFoldable>, { @@ -86,7 +91,12 @@ fn normalize(&self, span: Span, loc: Option, value: T) -> T /// signature types for implied bounds when checking regions. // FIXME(-Znext-solver): This should be removed when we compute implied outlives // bounds using the unnormalized signature of the function we're checking. - pub(super) fn deeply_normalize(&self, span: Span, loc: Option, value: T) -> T + pub(super) fn deeply_normalize( + &self, + span: Span, + loc: Option, + value: Unnormalized<'tcx, T>, + ) -> T where T: TypeFoldable>, { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 2cd0a05c723a..4d8c0a8a2d67 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -27,8 +27,8 @@ }; use rustc_middle::ty::{ self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity, - SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs, - UserSelfTy, + SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, Unnormalized, + UserArgs, UserSelfTy, }; use rustc_middle::{bug, span_bug}; use rustc_session::lint; @@ -423,7 +423,7 @@ pub(crate) fn apply_adjustments(&self, expr: &hir::Expr<'_>, adj: Vec(&self, span: Span, value: T) -> T + pub(crate) fn normalize(&self, span: Span, value: Unnormalized<'tcx, T>) -> T where T: TypeFoldable>, { diff --git a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs index 69c1eb9b3454..da81c9d4692e 100644 --- a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs +++ b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs @@ -13,7 +13,7 @@ use crate::traits::query::NoSolution; use crate::ty::{ self, EarlyBinder, FallibleTypeFolder, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeFolder, - TypeVisitableExt, + TypeVisitableExt, Unnormalized, }; #[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)] @@ -38,7 +38,11 @@ impl<'tcx> TyCtxt<'tcx> { /// This should only be used outside of type inference. For example, /// it assumes that normalization will succeed. #[tracing::instrument(level = "debug", skip(self, typing_env), ret)] - pub fn normalize_erasing_regions(self, typing_env: ty::TypingEnv<'tcx>, value: T) -> T + pub fn normalize_erasing_regions( + self, + typing_env: ty::TypingEnv<'tcx>, + value: Unnormalized<'tcx, T>, + ) -> T where T: TypeFoldable>, { @@ -69,7 +73,7 @@ pub fn normalize_erasing_regions(self, typing_env: ty::TypingEnv<'tcx>, value pub fn try_normalize_erasing_regions( self, typing_env: ty::TypingEnv<'tcx>, - value: T, + value: Unnormalized<'tcx, T>, ) -> Result> where T: TypeFoldable>, diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 567f660a5938..744d0a03c3e9 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -8,7 +8,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{ self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, - TypeVisitableExt, UniverseIndex, + TypeVisitableExt, UniverseIndex, Unnormalized, }; use tracing::instrument; @@ -19,7 +19,10 @@ /// Deeply normalize all aliases in `value`. This does not handle inference and expects /// its input to be already fully resolved. -pub fn deeply_normalize<'tcx, T, E>(at: At<'_, 'tcx>, value: T) -> Result> +pub fn deeply_normalize<'tcx, T, E>( + at: At<'_, 'tcx>, + value: Unnormalized<'tcx, T>, +) -> Result> where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, @@ -36,7 +39,7 @@ pub fn deeply_normalize<'tcx, T, E>(at: At<'_, 'tcx>, value: T) -> Result( at: At<'_, 'tcx>, - value: T, + value: Unnormalized<'tcx, T>, universes: Vec>, ) -> Result> where @@ -63,7 +66,7 @@ pub fn deeply_normalize_with_skipped_universes<'tcx, T, E>( /// the underlying infcx has any stalled coroutine def ids. pub fn deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals<'tcx, T, E>( at: At<'_, 'tcx>, - value: T, + value: Unnormalized<'tcx, T>, universes: Vec>, ) -> Result<(T, Vec>>), Vec> where diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index eee23a298449..a65eb2dda970 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -15,7 +15,7 @@ use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::relate::Relate; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast, Variance}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Unnormalized, Upcast, Variance}; use super::{FromSolverError, FulfillmentContext, ScrubbedTraitError, TraitEngine}; use crate::error_reporting::InferCtxtErrorExt; @@ -113,7 +113,7 @@ pub fn normalize>>( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: T, + value: Unnormalized<'tcx, T>, ) -> T { let infer_ok = self.infcx.at(cause, param_env).normalize(value); self.register_infer_ok_obligations(infer_ok) @@ -346,7 +346,7 @@ pub fn deeply_normalize>>( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: T, + value: Unnormalized<'tcx, T>, ) -> Result> { self.infcx.at(cause, param_env).deeply_normalize(value, &mut **self.engine.borrow_mut()) } @@ -355,7 +355,7 @@ pub fn structurally_normalize_ty( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: Ty<'tcx>, + value: Unnormalized<'tcx, Ty<'tcx>>, ) -> Result, Vec> { self.infcx .at(cause, param_env) @@ -366,7 +366,7 @@ pub fn structurally_normalize_const( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: ty::Const<'tcx>, + value: Unnormalized<'tcx, ty::Const<'tcx>>, ) -> Result, Vec> { self.infcx .at(cause, param_env) @@ -377,7 +377,7 @@ pub fn structurally_normalize_term( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: ty::Term<'tcx>, + value: Unnormalized<'tcx, ty::Term<'tcx>>, ) -> Result, Vec> { self.infcx .at(cause, param_env) diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 89a6132b0dc7..7b168e483431 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -180,7 +180,7 @@ pub enum TraitQueryMode { #[instrument(level = "debug", skip(cause, param_env, normalize_predicate))] pub fn predicates_for_generics<'tcx>( cause: impl Fn(usize, Span) -> ObligationCause<'tcx>, - mut normalize_predicate: impl FnMut(Clause<'tcx>) -> Clause<'tcx>, + mut normalize_predicate: impl FnMut(Unnormalized<'tcx, Clause<'tcx>>) -> Clause<'tcx>, param_env: ty::ParamEnv<'tcx>, generic_bounds: ty::InstantiatedPredicates<'tcx>, ) -> impl Iterator> { diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 65c4b40d4396..922a4049af4b 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -28,7 +28,10 @@ impl<'tcx> At<'_, 'tcx> { /// /// This normalization should be used when the type contains inference variables or the /// projection may be fallible. - fn normalize>>(&self, value: T) -> InferOk<'tcx, T> { + fn normalize>>( + &self, + value: Unnormalized<'tcx, T>, + ) -> InferOk<'tcx, T> { if self.infcx.next_trait_solver() { InferOk { value, obligations: PredicateObligations::new() } } else { @@ -53,7 +56,7 @@ fn normalize>>(&self, value: T) -> InferOk<'tcx, T> /// can remove the `fulfill_cx` parameter on this function. fn deeply_normalize( self, - value: T, + value: Unnormalized<'tcx, T>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, ) -> Result> where diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index ebeab8eddc6f..1287d866d467 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -9,7 +9,7 @@ impl<'tcx> At<'_, 'tcx> { fn structurally_normalize_ty( &self, - ty: Ty<'tcx>, + ty: Unnormalized<'tcx, Ty<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, ) -> Result, Vec> { self.structurally_normalize_term(ty.into(), fulfill_cx).map(|term| term.expect_type()) @@ -17,7 +17,7 @@ fn structurally_normalize_ty( fn structurally_normalize_const( &self, - ct: ty::Const<'tcx>, + ct: Unnormalized<'tcx, ty::Const<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, ) -> Result, Vec> { if self.infcx.tcx.features().generic_const_exprs() { @@ -29,7 +29,7 @@ fn structurally_normalize_const( fn structurally_normalize_term( &self, - term: ty::Term<'tcx>, + term: Unnormalized<'tcx, ty::Term<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, ) -> Result, Vec> { assert!(!term.is_infer(), "should have resolved vars before calling");