mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
make common normalization routines take Unnormalized
This commit is contained in:
@@ -207,7 +207,7 @@ pub(super) fn deeply_normalize<T>(&mut self, value: T, location: impl NormalizeL
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub(super) fn normalize_with_category<T>(
|
||||
&mut self,
|
||||
value: T,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
location: impl NormalizeLocation,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) -> T
|
||||
|
||||
@@ -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<Ty<'tcx>> {
|
||||
#[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(
|
||||
|
||||
@@ -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<T>(&self, span: Span, loc: Option<WellFormedLoc>, value: T) -> T
|
||||
fn normalize<T>(
|
||||
&self,
|
||||
span: Span,
|
||||
loc: Option<WellFormedLoc>,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
@@ -86,7 +91,12 @@ fn normalize<T>(&self, span: Span, loc: Option<WellFormedLoc>, 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<T>(&self, span: Span, loc: Option<WellFormedLoc>, value: T) -> T
|
||||
pub(super) fn deeply_normalize<T>(
|
||||
&self,
|
||||
span: Span,
|
||||
loc: Option<WellFormedLoc>,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
|
||||
@@ -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<Adjustment
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn normalize<T>(&self, span: Span, value: T) -> T
|
||||
pub(crate) fn normalize<T>(&self, span: Span, value: Unnormalized<'tcx, T>) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
|
||||
@@ -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<T>(self, typing_env: ty::TypingEnv<'tcx>, value: T) -> T
|
||||
pub fn normalize_erasing_regions<T>(
|
||||
self,
|
||||
typing_env: ty::TypingEnv<'tcx>,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
@@ -69,7 +73,7 @@ pub fn normalize_erasing_regions<T>(self, typing_env: ty::TypingEnv<'tcx>, value
|
||||
pub fn try_normalize_erasing_regions<T>(
|
||||
self,
|
||||
typing_env: ty::TypingEnv<'tcx>,
|
||||
value: T,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> Result<T, NormalizationError<'tcx>>
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
|
||||
@@ -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<T, Vec<E>>
|
||||
pub fn deeply_normalize<'tcx, T, E>(
|
||||
at: At<'_, 'tcx>,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> Result<T, Vec<E>>
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
E: FromSolverError<'tcx, NextSolverError<'tcx>>,
|
||||
@@ -36,7 +39,7 @@ pub fn deeply_normalize<'tcx, T, E>(at: At<'_, 'tcx>, value: T) -> Result<T, Vec
|
||||
/// `normalize_erasing_regions`, which skips binders as it walks through a type.
|
||||
pub fn deeply_normalize_with_skipped_universes<'tcx, T, E>(
|
||||
at: At<'_, 'tcx>,
|
||||
value: T,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
universes: Vec<Option<UniverseIndex>>,
|
||||
) -> Result<T, Vec<E>>
|
||||
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<Option<UniverseIndex>>,
|
||||
) -> Result<(T, Vec<Goal<'tcx, ty::Predicate<'tcx>>>), Vec<E>>
|
||||
where
|
||||
|
||||
@@ -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<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
&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<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
&self,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: T,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
) -> Result<T, Vec<E>> {
|
||||
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<Ty<'tcx>, Vec<E>> {
|
||||
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<ty::Const<'tcx>, Vec<E>> {
|
||||
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<ty::Term<'tcx>, Vec<E>> {
|
||||
self.infcx
|
||||
.at(cause, param_env)
|
||||
|
||||
@@ -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<Item = PredicateObligation<'tcx>> {
|
||||
|
||||
@@ -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<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> InferOk<'tcx, T> {
|
||||
fn normalize<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
&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<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> InferOk<'tcx, T>
|
||||
/// can remove the `fulfill_cx` parameter on this function.
|
||||
fn deeply_normalize<T, E>(
|
||||
self,
|
||||
value: T,
|
||||
value: Unnormalized<'tcx, T>,
|
||||
fulfill_cx: &mut dyn TraitEngine<'tcx, E>,
|
||||
) -> Result<T, Vec<E>>
|
||||
where
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
impl<'tcx> At<'_, 'tcx> {
|
||||
fn structurally_normalize_ty<E: 'tcx>(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
ty: Unnormalized<'tcx, Ty<'tcx>>,
|
||||
fulfill_cx: &mut dyn TraitEngine<'tcx, E>,
|
||||
) -> Result<Ty<'tcx>, Vec<E>> {
|
||||
self.structurally_normalize_term(ty.into(), fulfill_cx).map(|term| term.expect_type())
|
||||
@@ -17,7 +17,7 @@ fn structurally_normalize_ty<E: 'tcx>(
|
||||
|
||||
fn structurally_normalize_const<E: 'tcx>(
|
||||
&self,
|
||||
ct: ty::Const<'tcx>,
|
||||
ct: Unnormalized<'tcx, ty::Const<'tcx>>,
|
||||
fulfill_cx: &mut dyn TraitEngine<'tcx, E>,
|
||||
) -> Result<ty::Const<'tcx>, Vec<E>> {
|
||||
if self.infcx.tcx.features().generic_const_exprs() {
|
||||
@@ -29,7 +29,7 @@ fn structurally_normalize_const<E: 'tcx>(
|
||||
|
||||
fn structurally_normalize_term<E: 'tcx>(
|
||||
&self,
|
||||
term: ty::Term<'tcx>,
|
||||
term: Unnormalized<'tcx, ty::Term<'tcx>>,
|
||||
fulfill_cx: &mut dyn TraitEngine<'tcx, E>,
|
||||
) -> Result<ty::Term<'tcx>, Vec<E>> {
|
||||
assert!(!term.is_infer(), "should have resolved vars before calling");
|
||||
|
||||
Reference in New Issue
Block a user