Remove normalize_projection_type
This commit is contained in:
parent
3f2b2eee8f
commit
1930c77de1
4 changed files with 13 additions and 68 deletions
|
@ -8,14 +8,6 @@ use super::FulfillmentError;
|
|||
use super::{ObligationCause, PredicateObligation};
|
||||
|
||||
pub trait TraitEngine<'tcx>: 'tcx {
|
||||
fn normalize_projection_type(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) -> Ty<'tcx>;
|
||||
|
||||
/// Requires that `ty` must implement the trait with `def_id` in
|
||||
/// the given environment. This trait must not have any type
|
||||
/// parameters (except for `Self`).
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::errors::AutoDerefReachedRecursionLimit;
|
||||
use crate::infer::InferCtxtExt as _;
|
||||
use crate::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use crate::traits::{self, TraitEngine, TraitEngineExt};
|
||||
use rustc_hir as hir;
|
||||
|
@ -137,16 +138,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
|
||||
let normalized_ty = fulfillcx.normalize_projection_type(
|
||||
&self.infcx,
|
||||
self.param_env,
|
||||
ty::ProjectionTy {
|
||||
item_def_id: tcx.lang_items().deref_target()?,
|
||||
substs: trait_ref.substs,
|
||||
},
|
||||
let normalized_ty = self.infcx.partially_normalize_associated_types_in(
|
||||
cause,
|
||||
self.param_env,
|
||||
tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs),
|
||||
);
|
||||
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
|
||||
let normalized_ty =
|
||||
normalized_ty.into_value_registering_obligations(self.infcx, &mut *fulfillcx);
|
||||
let errors = fulfillcx.select_where_possible(&self.infcx);
|
||||
if !errors.is_empty() {
|
||||
// This shouldn't happen, except for evaluate/fulfill mismatches,
|
||||
|
|
|
@ -4,11 +4,11 @@ use crate::infer::canonical::OriginalQueryValues;
|
|||
use crate::infer::InferCtxt;
|
||||
use crate::traits::query::NoSolution;
|
||||
use crate::traits::{
|
||||
ChalkEnvironmentAndGoal, FulfillmentError, FulfillmentErrorCode, ObligationCause,
|
||||
PredicateObligation, SelectionError, TraitEngine,
|
||||
ChalkEnvironmentAndGoal, FulfillmentError, FulfillmentErrorCode, PredicateObligation,
|
||||
SelectionError, TraitEngine,
|
||||
};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitable};
|
||||
use rustc_middle::ty::{self, TypeVisitable};
|
||||
|
||||
pub struct FulfillmentContext<'tcx> {
|
||||
obligations: FxIndexSet<PredicateObligation<'tcx>>,
|
||||
|
@ -33,16 +33,6 @@ impl FulfillmentContext<'_> {
|
|||
}
|
||||
|
||||
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
fn normalize_projection_type(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
_param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
_cause: ObligationCause<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
infcx.tcx.mk_ty(ty::Projection(projection_ty))
|
||||
}
|
||||
|
||||
fn register_predicate_obligation(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
|
|
|
@ -4,12 +4,12 @@ use rustc_data_structures::obligation_forest::ProcessResult;
|
|||
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
|
||||
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
|
||||
use rustc_infer::traits::ProjectionCacheKey;
|
||||
use rustc_infer::traits::{SelectionError, TraitEngine, TraitEngineExt as _, TraitObligation};
|
||||
use rustc_infer::traits::{SelectionError, TraitEngine, TraitObligation};
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, Binder, Const, Ty, TypeVisitable};
|
||||
use rustc_middle::ty::{self, Binder, Const, TypeVisitable};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use super::const_evaluatable;
|
||||
|
@ -20,9 +20,9 @@ use super::CodeAmbiguity;
|
|||
use super::CodeProjectionError;
|
||||
use super::CodeSelectionError;
|
||||
use super::EvaluationResult;
|
||||
use super::PredicateObligation;
|
||||
use super::Unimplemented;
|
||||
use super::{FulfillmentError, FulfillmentErrorCode};
|
||||
use super::{ObligationCause, PredicateObligation};
|
||||
|
||||
use crate::traits::project::PolyProjectionObligation;
|
||||
use crate::traits::project::ProjectionCacheKeyExt as _;
|
||||
|
@ -126,42 +126,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
/// "Normalize" a projection type `<SomeType as SomeTrait>::X` by
|
||||
/// creating a fresh type variable `$0` as well as a projection
|
||||
/// predicate `<SomeType as SomeTrait>::X == $0`. When the
|
||||
/// inference engine runs, it will attempt to find an impl of
|
||||
/// `SomeTrait` or a where-clause that lets us unify `$0` with
|
||||
/// something concrete. If this fails, we'll unify `$0` with
|
||||
/// `projection_ty` again.
|
||||
#[instrument(level = "debug", skip(self, infcx, param_env, cause))]
|
||||
fn normalize_projection_type(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
debug_assert!(!projection_ty.has_escaping_bound_vars());
|
||||
|
||||
// FIXME(#20304) -- cache
|
||||
|
||||
let mut selcx = SelectionContext::new(infcx);
|
||||
let mut obligations = vec![];
|
||||
let normalized_ty = project::normalize_projection_type(
|
||||
&mut selcx,
|
||||
param_env,
|
||||
projection_ty,
|
||||
cause,
|
||||
0,
|
||||
&mut obligations,
|
||||
);
|
||||
self.register_predicate_obligations(infcx, obligations);
|
||||
|
||||
debug!(?normalized_ty);
|
||||
|
||||
normalized_ty.ty().unwrap()
|
||||
}
|
||||
|
||||
fn register_predicate_obligation(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
|
|
Loading…
Add table
Reference in a new issue