Auto merge of #125076 - compiler-errors:alias-term, r=lcnr
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
This commit is contained in:
commit
34582118af
73 changed files with 695 additions and 458 deletions
|
@ -29,7 +29,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
|
||||
|
||||
// Structurally normalize the lhs.
|
||||
let lhs = if let Some(alias) = lhs.to_alias_ty(self.tcx()) {
|
||||
let lhs = if let Some(alias) = lhs.to_alias_term() {
|
||||
let term = self.next_term_infer_of_kind(lhs);
|
||||
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
|
||||
term
|
||||
|
@ -38,7 +38,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
};
|
||||
|
||||
// Structurally normalize the rhs.
|
||||
let rhs = if let Some(alias) = rhs.to_alias_ty(self.tcx()) {
|
||||
let rhs = if let Some(alias) = rhs.to_alias_term() {
|
||||
let term = self.next_term_infer_of_kind(rhs);
|
||||
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
|
||||
term
|
||||
|
@ -56,7 +56,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
ty::AliasRelationDirection::Equate => ty::Variance::Invariant,
|
||||
ty::AliasRelationDirection::Subtype => ty::Variance::Covariant,
|
||||
};
|
||||
match (lhs.to_alias_ty(tcx), rhs.to_alias_ty(tcx)) {
|
||||
match (lhs.to_alias_term(), rhs.to_alias_term()) {
|
||||
(None, None) => {
|
||||
self.relate(param_env, lhs, variance, rhs)?;
|
||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
|
|
|
@ -699,7 +699,7 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
|
|||
old_ty,
|
||||
None,
|
||||
"{} has two generic parameters: {} and {}",
|
||||
proj.projection_ty,
|
||||
proj.projection_term,
|
||||
proj.term,
|
||||
old_ty.unwrap()
|
||||
);
|
||||
|
@ -740,7 +740,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
|
|||
// FIXME: Technically this equate could be fallible...
|
||||
self.nested.extend(
|
||||
self.ecx
|
||||
.eq_and_get_goals(self.param_env, alias_ty, proj.projection_ty)
|
||||
.eq_and_get_goals(
|
||||
self.param_env,
|
||||
alias_ty,
|
||||
proj.projection_term.expect_ty(self.ecx.tcx()),
|
||||
)
|
||||
.expect("expected to be able to unify goal projection with dyn's projection"),
|
||||
);
|
||||
proj.term.ty().unwrap()
|
||||
|
|
|
@ -748,7 +748,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
pub(super) fn relate_rigid_alias_non_alias(
|
||||
&mut self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
alias: ty::AliasTy<'tcx>,
|
||||
alias: ty::AliasTerm<'tcx>,
|
||||
variance: ty::Variance,
|
||||
term: ty::Term<'tcx>,
|
||||
) -> Result<(), NoSolution> {
|
||||
|
@ -765,13 +765,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
// Alternatively we could modify `Equate` for this case by adding another
|
||||
// variant to `StructurallyRelateAliases`.
|
||||
let identity_args = self.fresh_args_for_item(alias.def_id);
|
||||
let rigid_ctor = ty::AliasTy::new(tcx, alias.def_id, identity_args);
|
||||
let ctor_ty = rigid_ctor.to_ty(tcx);
|
||||
let rigid_ctor = ty::AliasTerm::new(tcx, alias.def_id, identity_args);
|
||||
let ctor_term = rigid_ctor.to_term(tcx);
|
||||
let InferOk { value: (), obligations } = self
|
||||
.infcx
|
||||
.at(&ObligationCause::dummy(), param_env)
|
||||
.trace(term, ctor_ty.into())
|
||||
.eq_structurally_relating_aliases(term, ctor_ty.into())?;
|
||||
.trace(term, ctor_term)
|
||||
.eq_structurally_relating_aliases(term, ctor_term)?;
|
||||
debug_assert!(obligations.is_empty());
|
||||
self.relate(param_env, alias, variance, rigid_ctor)
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,7 @@ use rustc_infer::infer::InferCtxt;
|
|||
use rustc_infer::traits::TraitEngineExt;
|
||||
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, UniverseIndex};
|
||||
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::{TypeFoldable, TypeVisitableExt};
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||
};
|
||||
|
||||
self.at.infcx.err_ctxt().report_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(data),
|
||||
OverflowCause::DeeplyNormalize(data.into()),
|
||||
self.at.cause.span,
|
||||
true,
|
||||
|_| {},
|
||||
|
@ -108,7 +108,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||
let recursion_limit = tcx.recursion_limit();
|
||||
if !recursion_limit.value_within_limit(self.depth) {
|
||||
self.at.infcx.err_ctxt().report_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(ty::AliasTy::new(tcx, uv.def, uv.args)),
|
||||
OverflowCause::DeeplyNormalize(uv.into()),
|
||||
self.at.cause.span,
|
||||
true,
|
||||
|_| {},
|
||||
|
@ -122,10 +122,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||
tcx,
|
||||
self.at.cause.clone(),
|
||||
self.at.param_env,
|
||||
ty::NormalizesTo {
|
||||
alias: AliasTy::new(tcx, uv.def, uv.args),
|
||||
term: new_infer_ct.into(),
|
||||
},
|
||||
ty::NormalizesTo { alias: uv.into(), term: new_infer_ct.into() },
|
||||
);
|
||||
|
||||
let result = if infcx.predicate_may_hold(&obligation) {
|
||||
|
|
|
@ -15,7 +15,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
|
||||
) -> QueryResult<'tcx> {
|
||||
let tcx = self.tcx();
|
||||
let inherent = goal.predicate.alias;
|
||||
let inherent = goal.predicate.alias.expect_ty(tcx);
|
||||
|
||||
let impl_def_id = tcx.parent(inherent.def_id);
|
||||
let impl_args = self.fresh_args_for_item(impl_def_id);
|
||||
|
|
|
@ -41,19 +41,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
Ok(res) => Ok(res),
|
||||
Err(NoSolution) => {
|
||||
let Goal { param_env, predicate: NormalizesTo { alias, term } } = goal;
|
||||
if alias.opt_kind(self.tcx()).is_some() {
|
||||
self.relate_rigid_alias_non_alias(
|
||||
param_env,
|
||||
alias,
|
||||
ty::Variance::Invariant,
|
||||
term,
|
||||
)?;
|
||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
} else {
|
||||
// FIXME(generic_const_exprs): we currently do not support rigid
|
||||
// unevaluated constants.
|
||||
Err(NoSolution)
|
||||
}
|
||||
self.relate_rigid_alias_non_alias(param_env, alias, ty::Variance::Invariant, term)?;
|
||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +122,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
ecx.eq(
|
||||
goal.param_env,
|
||||
goal.predicate.alias,
|
||||
assumption_projection_pred.projection_ty,
|
||||
assumption_projection_pred.projection_term,
|
||||
)?;
|
||||
|
||||
ecx.instantiate_normalizes_to_term(goal, assumption_projection_pred.term);
|
||||
|
@ -374,7 +363,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
|
||||
let pred = tupled_inputs_and_output
|
||||
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(
|
||||
projection_term: ty::AliasTerm::new(
|
||||
tcx,
|
||||
goal.predicate.def_id(),
|
||||
[goal.predicate.self_ty(), inputs],
|
||||
|
@ -426,9 +415,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
output_coroutine_ty,
|
||||
coroutine_return_ty,
|
||||
}| {
|
||||
let (projection_ty, term) = match tcx.item_name(goal.predicate.def_id()) {
|
||||
let (projection_term, term) = match tcx.item_name(goal.predicate.def_id()) {
|
||||
sym::CallOnceFuture => (
|
||||
ty::AliasTy::new(
|
||||
ty::AliasTerm::new(
|
||||
tcx,
|
||||
goal.predicate.def_id(),
|
||||
[goal.predicate.self_ty(), tupled_inputs_ty],
|
||||
|
@ -436,7 +425,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
output_coroutine_ty.into(),
|
||||
),
|
||||
sym::CallRefFuture => (
|
||||
ty::AliasTy::new(
|
||||
ty::AliasTerm::new(
|
||||
tcx,
|
||||
goal.predicate.def_id(),
|
||||
[
|
||||
|
@ -448,7 +437,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
output_coroutine_ty.into(),
|
||||
),
|
||||
sym::Output => (
|
||||
ty::AliasTy::new(
|
||||
ty::AliasTerm::new(
|
||||
tcx,
|
||||
goal.predicate.def_id(),
|
||||
[
|
||||
|
@ -460,7 +449,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
),
|
||||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
ty::ProjectionPredicate { projection_ty, term }
|
||||
ty::ProjectionPredicate { projection_term, term }
|
||||
},
|
||||
)
|
||||
.to_predicate(tcx);
|
||||
|
@ -637,7 +626,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
|
||||
goal,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||
projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||
term,
|
||||
}
|
||||
.to_predicate(tcx),
|
||||
|
@ -669,7 +658,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
|
||||
goal,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||
projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||
term,
|
||||
}
|
||||
.to_predicate(tcx),
|
||||
|
@ -753,7 +742,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
|||
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
|
||||
goal,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(
|
||||
projection_term: ty::AliasTerm::new(
|
||||
ecx.tcx(),
|
||||
goal.predicate.def_id(),
|
||||
[self_ty, coroutine.resume_ty()],
|
||||
|
|
|
@ -11,19 +11,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
|
||||
) -> QueryResult<'tcx> {
|
||||
let tcx = self.tcx();
|
||||
let projection_term = match goal.predicate.term.unpack() {
|
||||
ty::TermKind::Ty(_) => goal.predicate.projection_ty.to_ty(tcx).into(),
|
||||
ty::TermKind::Const(_) => ty::Const::new_unevaluated(
|
||||
tcx,
|
||||
ty::UnevaluatedConst::new(
|
||||
goal.predicate.projection_ty.def_id,
|
||||
goal.predicate.projection_ty.args,
|
||||
),
|
||||
tcx.type_of(goal.predicate.projection_ty.def_id)
|
||||
.instantiate(tcx, goal.predicate.projection_ty.args),
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
let projection_term = goal.predicate.projection_term.to_term(tcx);
|
||||
let goal = goal.with(
|
||||
tcx,
|
||||
ty::PredicateKind::AliasRelate(
|
||||
|
|
|
@ -540,11 +540,11 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
finished_map
|
||||
}
|
||||
|
||||
fn is_param_no_infer(&self, args: GenericArgsRef<'_>) -> bool {
|
||||
fn is_param_no_infer(&self, args: GenericArgsRef<'tcx>) -> bool {
|
||||
self.is_of_param(args.type_at(0)) && !args.types().any(|t| t.has_infer_types())
|
||||
}
|
||||
|
||||
pub fn is_of_param(&self, ty: Ty<'_>) -> bool {
|
||||
pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind() {
|
||||
ty::Param(_) => true,
|
||||
ty::Alias(ty::Projection, p) => self.is_of_param(p.self_ty()),
|
||||
|
@ -552,9 +552,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) -> bool {
|
||||
fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool {
|
||||
if let Some(ty) = p.term().skip_binder().ty() {
|
||||
matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_ty)
|
||||
matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_term.expect_ty(self.tcx))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -612,7 +612,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
// an inference variable.
|
||||
// Additionally, we check if we've seen this predicate before,
|
||||
// to avoid rendering duplicate bounds to the user.
|
||||
if self.is_param_no_infer(p.skip_binder().projection_ty.args)
|
||||
if self.is_param_no_infer(p.skip_binder().projection_term.args)
|
||||
&& !p.term().skip_binder().has_infer_types()
|
||||
&& is_new_pred
|
||||
{
|
||||
|
@ -684,7 +684,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
// and turn them into an explicit negative impl for our type.
|
||||
debug!("Projecting and unifying projection predicate {:?}", predicate);
|
||||
|
||||
match project::poly_project_and_unify_type(selcx, &obligation.with(self.tcx, p))
|
||||
match project::poly_project_and_unify_term(selcx, &obligation.with(self.tcx, p))
|
||||
{
|
||||
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
|
||||
debug!(
|
||||
|
|
|
@ -1096,11 +1096,11 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
|
|||
Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(tr))) => tr.trait_ref,
|
||||
Some(ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)))
|
||||
if matches!(
|
||||
infcx.tcx.def_kind(proj.projection_ty.def_id),
|
||||
infcx.tcx.def_kind(proj.projection_term.def_id),
|
||||
DefKind::AssocTy | DefKind::AssocConst
|
||||
) =>
|
||||
{
|
||||
proj.projection_ty.trait_ref(infcx.tcx)
|
||||
proj.projection_term.trait_ref(infcx.tcx)
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
|
|
@ -1105,9 +1105,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
.iter()
|
||||
.find_map(|pred| {
|
||||
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
||||
&& Some(proj.projection_term.def_id) == self.tcx.lang_items().fn_once_output()
|
||||
// args tuple will always be args[1]
|
||||
&& let ty::Tuple(args) = proj.projection_ty.args.type_at(1).kind()
|
||||
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
|
||||
{
|
||||
Some((
|
||||
DefIdOrName::DefId(def_id),
|
||||
|
@ -1149,10 +1149,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
};
|
||||
param_env.caller_bounds().iter().find_map(|pred| {
|
||||
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
||||
&& proj.projection_ty.self_ty() == found
|
||||
&& Some(proj.projection_term.def_id) == self.tcx.lang_items().fn_once_output()
|
||||
&& proj.projection_term.self_ty() == found
|
||||
// args tuple will always be args[1]
|
||||
&& let ty::Tuple(args) = proj.projection_ty.args.type_at(1).kind()
|
||||
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
|
||||
{
|
||||
Some((
|
||||
name,
|
||||
|
@ -3846,11 +3846,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&& let Some(found) = failed_pred.skip_binder().term.ty()
|
||||
{
|
||||
type_diffs = vec![Sorts(ty::error::ExpectedFound {
|
||||
expected: Ty::new_alias(
|
||||
self.tcx,
|
||||
ty::Projection,
|
||||
where_pred.skip_binder().projection_ty,
|
||||
),
|
||||
expected: where_pred
|
||||
.skip_binder()
|
||||
.projection_term
|
||||
.expect_ty(self.tcx)
|
||||
.to_ty(self.tcx),
|
||||
found,
|
||||
})];
|
||||
}
|
||||
|
@ -4275,7 +4275,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(self.tcx, proj.def_id, args),
|
||||
projection_term: ty::AliasTerm::new(self.tcx, proj.def_id, args),
|
||||
term: ty.into(),
|
||||
}),
|
||||
));
|
||||
|
@ -4972,7 +4972,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
|
|||
let ty::ClauseKind::Projection(proj) = clause else {
|
||||
return;
|
||||
};
|
||||
let name = tcx.item_name(proj.projection_ty.def_id);
|
||||
let name = tcx.item_name(proj.projection_term.def_id);
|
||||
let mut predicates = generics.predicates.iter().peekable();
|
||||
let mut prev: Option<&hir::WhereBoundPredicate<'_>> = None;
|
||||
while let Some(pred) = predicates.next() {
|
||||
|
|
|
@ -63,7 +63,7 @@ use super::{
|
|||
pub use rustc_infer::traits::error_reporting::*;
|
||||
|
||||
pub enum OverflowCause<'tcx> {
|
||||
DeeplyNormalize(ty::AliasTy<'tcx>),
|
||||
DeeplyNormalize(ty::AliasTerm<'tcx>),
|
||||
TraitSolver(ty::Predicate<'tcx>),
|
||||
}
|
||||
|
||||
|
@ -247,10 +247,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
let mut err = match cause {
|
||||
OverflowCause::DeeplyNormalize(alias_ty) => {
|
||||
let alias_ty = self.resolve_vars_if_possible(alias_ty);
|
||||
let kind = alias_ty.opt_kind(self.tcx).map_or("alias", |k| k.descr());
|
||||
let alias_str = with_short_path(self.tcx, alias_ty);
|
||||
OverflowCause::DeeplyNormalize(alias_term) => {
|
||||
let alias_term = self.resolve_vars_if_possible(alias_term);
|
||||
let kind = alias_term.kind(self.tcx).descr();
|
||||
let alias_str = with_short_path(self.tcx, alias_term);
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
|
@ -1469,7 +1469,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
);
|
||||
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
self.can_eq(param_env, goal.projection_ty, assumption.projection_ty)
|
||||
self.can_eq(param_env, goal.projection_term, assumption.projection_term)
|
||||
&& self.can_eq(param_env, goal.term, assumption.term)
|
||||
}
|
||||
|
||||
|
@ -1584,23 +1584,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
infer::BoundRegionConversionTime::HigherRankedType,
|
||||
bound_predicate.rebind(data),
|
||||
);
|
||||
let unnormalized_term = match data.term.unpack() {
|
||||
ty::TermKind::Ty(_) => Ty::new_projection(
|
||||
self.tcx,
|
||||
data.projection_ty.def_id,
|
||||
data.projection_ty.args,
|
||||
)
|
||||
.into(),
|
||||
ty::TermKind::Const(ct) => ty::Const::new_unevaluated(
|
||||
self.tcx,
|
||||
ty::UnevaluatedConst {
|
||||
def: data.projection_ty.def_id,
|
||||
args: data.projection_ty.args,
|
||||
},
|
||||
ct.ty(),
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
let unnormalized_term = data.projection_term.to_term(self.tcx);
|
||||
// FIXME(-Znext-solver): For diagnostic purposes, it would be nice
|
||||
// to deeply normalize this type.
|
||||
let normalized_term =
|
||||
|
@ -1665,13 +1649,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
return None;
|
||||
};
|
||||
|
||||
let trait_assoc_item = self.tcx.opt_associated_item(proj.projection_ty.def_id)?;
|
||||
let trait_assoc_item = self.tcx.opt_associated_item(proj.projection_term.def_id)?;
|
||||
let trait_assoc_ident = trait_assoc_item.ident(self.tcx);
|
||||
|
||||
let mut associated_items = vec![];
|
||||
self.tcx.for_each_relevant_impl(
|
||||
self.tcx.trait_of_item(proj.projection_ty.def_id)?,
|
||||
proj.projection_ty.self_ty(),
|
||||
self.tcx.trait_of_item(proj.projection_term.def_id)?,
|
||||
proj.projection_term.self_ty(),
|
||||
|impl_def_id| {
|
||||
associated_items.extend(
|
||||
self.tcx
|
||||
|
@ -1740,11 +1724,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
normalized_ty: ty::Term<'tcx>,
|
||||
expected_ty: ty::Term<'tcx>,
|
||||
) -> Option<String> {
|
||||
let trait_def_id = pred.projection_ty.trait_def_id(self.tcx);
|
||||
let self_ty = pred.projection_ty.self_ty();
|
||||
let trait_def_id = pred.projection_term.trait_def_id(self.tcx);
|
||||
let self_ty = pred.projection_term.self_ty();
|
||||
|
||||
with_forced_trimmed_paths! {
|
||||
if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() {
|
||||
if Some(pred.projection_term.def_id) == self.tcx.lang_items().fn_once_output() {
|
||||
let fn_kind = self_ty.prefix_string(self.tcx);
|
||||
let item = match self_ty.kind() {
|
||||
ty::FnDef(def, _) => self.tcx.item_name(*def).to_string(),
|
||||
|
@ -2623,14 +2607,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
if let Err(guar) =
|
||||
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_ty.def_id))
|
||||
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_term.def_id))
|
||||
{
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
return guar;
|
||||
}
|
||||
let arg = data
|
||||
.projection_ty
|
||||
.projection_term
|
||||
.args
|
||||
.iter()
|
||||
.chain(Some(data.term.into_arg()))
|
||||
|
|
|
@ -771,13 +771,13 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
match project::poly_project_and_unify_type(&mut self.selcx, &project_obligation) {
|
||||
match project::poly_project_and_unify_term(&mut self.selcx, &project_obligation) {
|
||||
ProjectAndUnifyResult::Holds(os) => ProcessResult::Changed(mk_pending(os)),
|
||||
ProjectAndUnifyResult::FailedNormalization => {
|
||||
stalled_on.clear();
|
||||
stalled_on.extend(args_infer_vars(
|
||||
&self.selcx,
|
||||
project_obligation.predicate.map_bound(|pred| pred.projection_ty.args),
|
||||
project_obligation.predicate.map_bound(|pred| pred.projection_term.args),
|
||||
));
|
||||
ProcessResult::Unchanged
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub use self::object_safety::hir_ty_lowering_object_safety_violations;
|
|||
pub use self::object_safety::is_vtable_safe_method;
|
||||
pub use self::object_safety::object_safety_violations_for_assoc_item;
|
||||
pub use self::object_safety::ObjectSafetyViolation;
|
||||
pub use self::project::{normalize_inherent_projection, normalize_projection_type};
|
||||
pub use self::project::{normalize_inherent_projection, normalize_projection_ty};
|
||||
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
|
||||
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};
|
||||
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
|
||||
|
|
|
@ -213,7 +213,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
let recursion_limit = self.interner().recursion_limit();
|
||||
if !recursion_limit.value_within_limit(self.depth) {
|
||||
self.selcx.infcx.err_ctxt().report_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(data),
|
||||
OverflowCause::DeeplyNormalize(data.into()),
|
||||
self.cause.span,
|
||||
true,
|
||||
|_| {},
|
||||
|
@ -238,7 +238,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
// register an obligation to *later* project, since we know
|
||||
// there won't be bound vars there.
|
||||
let data = data.fold_with(self);
|
||||
let normalized_ty = project::normalize_projection_type(
|
||||
let normalized_ty = project::normalize_projection_ty(
|
||||
self.selcx,
|
||||
self.param_env,
|
||||
data,
|
||||
|
@ -273,10 +273,10 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
let (data, mapped_regions, mapped_types, mapped_consts) =
|
||||
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, data);
|
||||
let data = data.fold_with(self);
|
||||
let normalized_ty = project::opt_normalize_projection_type(
|
||||
let normalized_ty = project::opt_normalize_projection_term(
|
||||
self.selcx,
|
||||
self.param_env,
|
||||
data,
|
||||
data.into(),
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
self.obligations,
|
||||
|
@ -309,7 +309,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
let recursion_limit = self.interner().recursion_limit();
|
||||
if !recursion_limit.value_within_limit(self.depth) {
|
||||
self.selcx.infcx.err_ctxt().report_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(data),
|
||||
OverflowCause::DeeplyNormalize(data.into()),
|
||||
self.cause.span,
|
||||
false,
|
||||
|diag| {
|
||||
|
|
|
@ -305,7 +305,7 @@ fn predicate_references_self<'tcx>(
|
|||
//
|
||||
// This is ALT2 in issue #56288, see that for discussion of the
|
||||
// possible alternatives.
|
||||
data.projection_ty.args[1..].iter().any(has_self_ty).then_some(sp)
|
||||
data.projection_term.args[1..].iter().any(has_self_ty).then_some(sp)
|
||||
}
|
||||
ty::ClauseKind::ConstArgHasType(_ct, ty) => has_self_ty(&ty.into()).then_some(sp),
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::PredicateObligation;
|
|||
use super::Selection;
|
||||
use super::SelectionContext;
|
||||
use super::SelectionError;
|
||||
use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
|
||||
use super::{Normalized, NormalizedTerm, ProjectionCacheEntry, ProjectionCacheKey};
|
||||
use rustc_infer::traits::ObligationCauseCode;
|
||||
use rustc_middle::traits::BuiltinImplSource;
|
||||
use rustc_middle::traits::ImplSource;
|
||||
|
@ -44,7 +44,7 @@ pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPre
|
|||
|
||||
pub type ProjectionObligation<'tcx> = Obligation<'tcx, ty::ProjectionPredicate<'tcx>>;
|
||||
|
||||
pub type ProjectionTyObligation<'tcx> = Obligation<'tcx, ty::AliasTy<'tcx>>;
|
||||
pub type ProjectionTermObligation<'tcx> = Obligation<'tcx, ty::AliasTerm<'tcx>>;
|
||||
|
||||
pub(super) struct InProgress;
|
||||
|
||||
|
@ -182,7 +182,7 @@ pub(super) enum ProjectAndUnifyResult<'tcx> {
|
|||
/// If successful, this may result in additional obligations. Also returns
|
||||
/// the projection cache key used to track these additional obligations.
|
||||
#[instrument(level = "debug", skip(selcx))]
|
||||
pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
|
||||
pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &PolyProjectionObligation<'tcx>,
|
||||
) -> ProjectAndUnifyResult<'tcx> {
|
||||
|
@ -193,7 +193,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
|
|||
let new_universe = infcx.universe();
|
||||
|
||||
let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
|
||||
match project_and_unify_type(selcx, &placeholder_obligation) {
|
||||
match project_and_unify_term(selcx, &placeholder_obligation) {
|
||||
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
|
||||
ProjectAndUnifyResult::Holds(obligations)
|
||||
if old_universe != new_universe
|
||||
|
@ -233,19 +233,19 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
|
|||
/// ```
|
||||
/// If successful, this may result in additional obligations.
|
||||
///
|
||||
/// See [poly_project_and_unify_type] for an explanation of the return value.
|
||||
/// See [poly_project_and_unify_term] for an explanation of the return value.
|
||||
#[instrument(level = "debug", skip(selcx))]
|
||||
fn project_and_unify_type<'cx, 'tcx>(
|
||||
fn project_and_unify_term<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionObligation<'tcx>,
|
||||
) -> ProjectAndUnifyResult<'tcx> {
|
||||
let mut obligations = vec![];
|
||||
|
||||
let infcx = selcx.infcx;
|
||||
let normalized = match opt_normalize_projection_type(
|
||||
let normalized = match opt_normalize_projection_term(
|
||||
selcx,
|
||||
obligation.param_env,
|
||||
obligation.predicate.projection_ty,
|
||||
obligation.predicate.projection_term,
|
||||
obligation.cause.clone(),
|
||||
obligation.recursion_depth,
|
||||
&mut obligations,
|
||||
|
@ -291,7 +291,7 @@ fn project_and_unify_type<'cx, 'tcx>(
|
|||
/// there are unresolved type variables in the projection, we will
|
||||
/// instantiate it with a fresh type variable `$X` and generate a new
|
||||
/// obligation `<T as Trait>::Item == $X` for later.
|
||||
pub fn normalize_projection_type<'a, 'b, 'tcx>(
|
||||
pub fn normalize_projection_ty<'a, 'b, 'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
|
@ -299,10 +299,10 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
|
|||
depth: usize,
|
||||
obligations: &mut Vec<PredicateObligation<'tcx>>,
|
||||
) -> Term<'tcx> {
|
||||
opt_normalize_projection_type(
|
||||
opt_normalize_projection_term(
|
||||
selcx,
|
||||
param_env,
|
||||
projection_ty,
|
||||
projection_ty.into(),
|
||||
cause.clone(),
|
||||
depth,
|
||||
obligations,
|
||||
|
@ -314,7 +314,10 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
|
|||
// and a deferred predicate to resolve this when more type
|
||||
// information is available.
|
||||
|
||||
selcx.infcx.infer_projection(param_env, projection_ty, cause, depth + 1, obligations).into()
|
||||
selcx
|
||||
.infcx
|
||||
.projection_ty_to_infer(param_env, projection_ty, cause, depth + 1, obligations)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -329,10 +332,10 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
|
|||
/// function takes an obligations vector and appends to it directly, which is
|
||||
/// slightly uglier but avoids the need for an extra short-lived allocation.
|
||||
#[instrument(level = "debug", skip(selcx, param_env, cause, obligations))]
|
||||
pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
||||
pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
projection_term: ty::AliasTerm<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize,
|
||||
obligations: &mut Vec<PredicateObligation<'tcx>>,
|
||||
|
@ -344,8 +347,8 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
|||
// mode, which could lead to using incorrect cache results.
|
||||
let use_cache = !selcx.is_intercrate();
|
||||
|
||||
let projection_ty = infcx.resolve_vars_if_possible(projection_ty);
|
||||
let cache_key = ProjectionCacheKey::new(projection_ty, param_env);
|
||||
let projection_term = infcx.resolve_vars_if_possible(projection_term);
|
||||
let cache_key = ProjectionCacheKey::new(projection_term, param_env);
|
||||
|
||||
// FIXME(#20304) For now, I am caching here, which is good, but it
|
||||
// means we don't capture the type variables that are created in
|
||||
|
@ -393,7 +396,7 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
|||
debug!("recur cache");
|
||||
return Err(InProgress);
|
||||
}
|
||||
Err(ProjectionCacheEntry::NormalizedTy { ty, complete: _ }) => {
|
||||
Err(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
|
||||
// This is the hottest path in this function.
|
||||
//
|
||||
// If we find the value in the cache, then return it along
|
||||
|
@ -411,14 +414,14 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
|||
}
|
||||
Err(ProjectionCacheEntry::Error) => {
|
||||
debug!("opt_normalize_projection_type: found error");
|
||||
let result = normalize_to_error(selcx, param_env, projection_ty, cause, depth);
|
||||
let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
|
||||
obligations.extend(result.obligations);
|
||||
return Ok(Some(result.value.into()));
|
||||
}
|
||||
}
|
||||
|
||||
let obligation =
|
||||
Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_ty);
|
||||
Obligation::with_depth(selcx.tcx(), cause.clone(), depth, param_env, projection_term);
|
||||
|
||||
match project(selcx, &obligation) {
|
||||
Ok(Projected::Progress(Progress {
|
||||
|
@ -481,7 +484,7 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
|||
if use_cache {
|
||||
infcx.inner.borrow_mut().projection_cache().error(cache_key);
|
||||
}
|
||||
let result = normalize_to_error(selcx, param_env, projection_ty, cause, depth);
|
||||
let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
|
||||
obligations.extend(result.obligations);
|
||||
Ok(Some(result.value.into()))
|
||||
}
|
||||
|
@ -510,19 +513,33 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
|
|||
fn normalize_to_error<'a, 'tcx>(
|
||||
selcx: &SelectionContext<'a, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
projection_term: ty::AliasTerm<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize,
|
||||
) -> NormalizedTy<'tcx> {
|
||||
let trait_ref = ty::Binder::dummy(projection_ty.trait_ref(selcx.tcx()));
|
||||
) -> NormalizedTerm<'tcx> {
|
||||
let trait_ref = ty::Binder::dummy(projection_term.trait_ref(selcx.tcx()));
|
||||
let new_value = match projection_term.kind(selcx.tcx()) {
|
||||
ty::AliasTermKind::ProjectionTy
|
||||
| ty::AliasTermKind::InherentTy
|
||||
| ty::AliasTermKind::OpaqueTy
|
||||
| ty::AliasTermKind::WeakTy => selcx.infcx.next_ty_var(cause.span).into(),
|
||||
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst => selcx
|
||||
.infcx
|
||||
.next_const_var(
|
||||
selcx
|
||||
.tcx()
|
||||
.type_of(projection_term.def_id)
|
||||
.instantiate(selcx.tcx(), projection_term.args),
|
||||
cause.span,
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
let trait_obligation = Obligation {
|
||||
cause,
|
||||
recursion_depth: depth,
|
||||
param_env,
|
||||
predicate: trait_ref.to_predicate(selcx.tcx()),
|
||||
};
|
||||
let tcx = selcx.infcx.tcx;
|
||||
let new_value = selcx.infcx.next_ty_var(tcx.def_span(projection_ty.def_id));
|
||||
Normalized { value: new_value, obligations: vec![trait_obligation] }
|
||||
}
|
||||
|
||||
|
@ -676,7 +693,7 @@ impl<'tcx> Progress<'tcx> {
|
|||
#[instrument(level = "info", skip(selcx))]
|
||||
fn project<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
) -> Result<Projected<'tcx>, ProjectionError<'tcx>> {
|
||||
if !selcx.tcx().recursion_limit().value_within_limit(obligation.recursion_depth) {
|
||||
// This should really be an immediate error, but some existing code
|
||||
|
@ -751,7 +768,7 @@ fn project<'cx, 'tcx>(
|
|||
/// there that can answer this question.
|
||||
fn assemble_candidates_from_param_env<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate_set: &mut ProjectionCandidateSet<'tcx>,
|
||||
) {
|
||||
assemble_candidates_from_predicates(
|
||||
|
@ -776,7 +793,7 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>(
|
|||
/// Here, for example, we could conclude that the result is `i32`.
|
||||
fn assemble_candidates_from_trait_def<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate_set: &mut ProjectionCandidateSet<'tcx>,
|
||||
) {
|
||||
debug!("assemble_candidates_from_trait_def(..)");
|
||||
|
@ -834,7 +851,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
|
|||
/// `dyn Iterator<Item = ()>: Iterator` again.
|
||||
fn assemble_candidates_from_object_ty<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate_set: &mut ProjectionCandidateSet<'tcx>,
|
||||
) {
|
||||
debug!("assemble_candidates_from_object_ty(..)");
|
||||
|
@ -878,7 +895,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
|
|||
)]
|
||||
fn assemble_candidates_from_predicates<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate_set: &mut ProjectionCandidateSet<'tcx>,
|
||||
ctor: fn(ty::PolyProjectionPredicate<'tcx>) -> ProjectionCandidate<'tcx>,
|
||||
env_predicates: impl Iterator<Item = ty::Clause<'tcx>>,
|
||||
|
@ -926,7 +943,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
|
|||
#[instrument(level = "debug", skip(selcx, obligation, candidate_set))]
|
||||
fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate_set: &mut ProjectionCandidateSet<'tcx>,
|
||||
) {
|
||||
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
|
||||
|
@ -1254,7 +1271,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
|
||||
fn confirm_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
candidate: ProjectionCandidate<'tcx>,
|
||||
) -> Progress<'tcx> {
|
||||
debug!(?obligation, ?candidate, "confirm_candidate");
|
||||
|
@ -1286,7 +1303,7 @@ fn confirm_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_select_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
impl_source: Selection<'tcx>,
|
||||
) -> Progress<'tcx> {
|
||||
match impl_source {
|
||||
|
@ -1334,7 +1351,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_coroutine_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
|
||||
|
@ -1378,7 +1395,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
|||
};
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: ty.into(),
|
||||
};
|
||||
|
||||
|
@ -1389,7 +1406,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_future_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
|
||||
|
@ -1422,7 +1439,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
|||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: return_ty.into(),
|
||||
};
|
||||
|
||||
|
@ -1433,7 +1450,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_iterator_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
|
||||
|
@ -1464,7 +1481,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
|
|||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: yield_ty.into(),
|
||||
};
|
||||
|
||||
|
@ -1475,7 +1492,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let ty::Coroutine(_, args) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
|
||||
|
@ -1514,7 +1531,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
|||
let item_ty = args.type_at(0);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
projection_term: ty::AliasTerm::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: item_ty.into(),
|
||||
};
|
||||
|
||||
|
@ -1525,7 +1542,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
data: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -1583,8 +1600,10 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
|
||||
};
|
||||
|
||||
let predicate =
|
||||
ty::ProjectionPredicate { projection_ty: ty::AliasTy::new(tcx, item_def_id, args), term };
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new(tcx, item_def_id, args),
|
||||
term,
|
||||
};
|
||||
|
||||
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||
.with_addl_obligations(obligations)
|
||||
|
@ -1593,7 +1612,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_fn_pointer_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -1629,7 +1648,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_closure_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -1728,7 +1747,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_callable_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
fn_sig: ty::PolyFnSig<'tcx>,
|
||||
flag: util::TupleArgumentsFlag,
|
||||
fn_host_effect: ty::Const<'tcx>,
|
||||
|
@ -1749,7 +1768,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
|||
fn_host_effect,
|
||||
)
|
||||
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(tcx, fn_once_output_def_id, trait_ref.args),
|
||||
projection_term: ty::AliasTerm::new(tcx, fn_once_output_def_id, trait_ref.args),
|
||||
term: ret_type.into(),
|
||||
});
|
||||
|
||||
|
@ -1758,7 +1777,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_async_closure_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -1837,13 +1856,13 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
sym::Output => sig.return_ty,
|
||||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
let projection_ty = match item_name {
|
||||
sym::CallOnceFuture | sym::Output => ty::AliasTy::new(
|
||||
let projection_term = match item_name {
|
||||
sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
[self_ty, sig.tupled_inputs_ty],
|
||||
),
|
||||
sym::CallRefFuture => ty::AliasTy::new(
|
||||
sym::CallRefFuture => ty::AliasTerm::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
[ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()],
|
||||
|
@ -1852,7 +1871,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
};
|
||||
|
||||
args.coroutine_closure_sig()
|
||||
.rebind(ty::ProjectionPredicate { projection_ty, term: term.into() })
|
||||
.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
|
||||
}
|
||||
ty::FnDef(..) | ty::FnPtr(..) => {
|
||||
let bound_sig = self_ty.fn_sig(tcx);
|
||||
|
@ -1872,13 +1891,13 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
}
|
||||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
let projection_ty = match item_name {
|
||||
sym::CallOnceFuture | sym::Output => ty::AliasTy::new(
|
||||
let projection_term = match item_name {
|
||||
sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
[self_ty, Ty::new_tup(tcx, sig.inputs())],
|
||||
),
|
||||
sym::CallRefFuture => ty::AliasTy::new(
|
||||
sym::CallRefFuture => ty::AliasTerm::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
[
|
||||
|
@ -1890,7 +1909,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
|
||||
bound_sig.rebind(ty::ProjectionPredicate { projection_ty, term: term.into() })
|
||||
bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
|
||||
}
|
||||
ty::Closure(_, args) => {
|
||||
let args = args.as_closure();
|
||||
|
@ -1911,11 +1930,11 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
}
|
||||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
let projection_ty = match item_name {
|
||||
let projection_term = match item_name {
|
||||
sym::CallOnceFuture | sym::Output => {
|
||||
ty::AliasTy::new(tcx, obligation.predicate.def_id, [self_ty, sig.inputs()[0]])
|
||||
ty::AliasTerm::new(tcx, obligation.predicate.def_id, [self_ty, sig.inputs()[0]])
|
||||
}
|
||||
sym::CallRefFuture => ty::AliasTy::new(
|
||||
sym::CallRefFuture => ty::AliasTerm::new(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
[ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()],
|
||||
|
@ -1923,7 +1942,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
name => bug!("no such associated type: {name}"),
|
||||
};
|
||||
|
||||
bound_sig.rebind(ty::ProjectionPredicate { projection_ty, term: term.into() })
|
||||
bound_sig.rebind(ty::ProjectionPredicate { projection_term, term: term.into() })
|
||||
}
|
||||
_ => bug!("expected callable type for AsyncFn candidate"),
|
||||
};
|
||||
|
@ -1934,7 +1953,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let [
|
||||
|
@ -1951,7 +1970,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
|
|||
};
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy::new(
|
||||
projection_term: ty::AliasTerm::new(
|
||||
selcx.tcx(),
|
||||
obligation.predicate.def_id,
|
||||
obligation.predicate.args,
|
||||
|
@ -1973,7 +1992,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_param_env_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
poly_cache_entry: ty::PolyProjectionPredicate<'tcx>,
|
||||
potentially_unnormalized_candidate: bool,
|
||||
) -> Progress<'tcx> {
|
||||
|
@ -1987,7 +2006,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
|
|||
poly_cache_entry,
|
||||
);
|
||||
|
||||
let cache_projection = cache_entry.projection_ty;
|
||||
let cache_projection = cache_entry.projection_term;
|
||||
let mut nested_obligations = Vec::new();
|
||||
let obligation_projection = obligation.predicate;
|
||||
let obligation_projection = ensure_sufficient_stack(|| {
|
||||
|
@ -2042,7 +2061,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
|
|||
|
||||
fn confirm_impl_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
impl_impl_source: ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -2103,7 +2122,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
|||
// associated type itself.
|
||||
fn assoc_ty_own_obligations<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
nested: &mut Vec<PredicateObligation<'tcx>>,
|
||||
) {
|
||||
let tcx = selcx.tcx();
|
||||
|
@ -2165,7 +2184,7 @@ impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
|
|||
// from a specific call to `opt_normalize_projection_type` - if
|
||||
// there's no precise match, the original cache entry is "stranded"
|
||||
// anyway.
|
||||
infcx.resolve_vars_if_possible(predicate.projection_ty),
|
||||
infcx.resolve_vars_if_possible(predicate.projection_term),
|
||||
obligation.param_env,
|
||||
)
|
||||
})
|
||||
|
|
|
@ -222,7 +222,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
|
|||
.infcx
|
||||
.err_ctxt()
|
||||
.build_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(data),
|
||||
OverflowCause::DeeplyNormalize(data.into()),
|
||||
self.cause.span,
|
||||
true,
|
||||
)
|
||||
|
|
|
@ -945,7 +945,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
self.infcx.probe(|_| {
|
||||
let ty = traits::normalize_projection_type(
|
||||
let ty = traits::normalize_projection_ty(
|
||||
self,
|
||||
param_env,
|
||||
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
|
||||
|
|
|
@ -8,7 +8,7 @@ use self::SelectionCandidate::*;
|
|||
use super::coherence::{self, Conflict};
|
||||
use super::const_evaluatable;
|
||||
use super::project;
|
||||
use super::project::ProjectionTyObligation;
|
||||
use super::project::ProjectionTermObligation;
|
||||
use super::util;
|
||||
use super::util::closure_trait_ref_and_return_type;
|
||||
use super::wf;
|
||||
|
@ -809,7 +809,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
|
||||
let data = bound_predicate.rebind(data);
|
||||
let project_obligation = obligation.with(self.tcx(), data);
|
||||
match project::poly_project_and_unify_type(self, &project_obligation) {
|
||||
match project::poly_project_and_unify_term(self, &project_obligation) {
|
||||
ProjectAndUnifyResult::Holds(mut subobligations) => {
|
||||
'compute_res: {
|
||||
// If we've previously marked this projection as 'complete', then
|
||||
|
@ -1734,7 +1734,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
/// in cases like #91762.
|
||||
pub(super) fn match_projection_projections(
|
||||
&mut self,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation: &ProjectionTermObligation<'tcx>,
|
||||
env_predicate: PolyProjectionPredicate<'tcx>,
|
||||
potentially_unnormalized_candidates: bool,
|
||||
) -> ProjectionMatchesProjection {
|
||||
|
@ -1753,12 +1753,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation.param_env,
|
||||
obligation.cause.clone(),
|
||||
obligation.recursion_depth + 1,
|
||||
infer_predicate.projection_ty,
|
||||
infer_predicate.projection_term,
|
||||
&mut nested_obligations,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
infer_predicate.projection_ty
|
||||
infer_predicate.projection_term
|
||||
};
|
||||
|
||||
let is_match = self
|
||||
|
|
|
@ -166,11 +166,8 @@ pub fn clause_obligations<'tcx>(
|
|||
wf.compute(ty.into());
|
||||
}
|
||||
ty::ClauseKind::Projection(t) => {
|
||||
wf.compute_alias(t.projection_ty);
|
||||
wf.compute(match t.term.unpack() {
|
||||
ty::TermKind::Ty(ty) => ty.into(),
|
||||
ty::TermKind::Const(c) => c.into(),
|
||||
})
|
||||
wf.compute_alias_term(t.projection_term);
|
||||
wf.compute(t.term.into_arg());
|
||||
}
|
||||
ty::ClauseKind::ConstArgHasType(ct, ty) => {
|
||||
wf.compute(ct.into());
|
||||
|
@ -440,7 +437,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
|
||||
/// Pushes the obligations required for an alias (except inherent) to be WF
|
||||
/// into `self.out`.
|
||||
fn compute_alias(&mut self, data: ty::AliasTy<'tcx>) {
|
||||
fn compute_alias_ty(&mut self, data: ty::AliasTy<'tcx>) {
|
||||
self.compute_alias_term(data.into());
|
||||
}
|
||||
|
||||
/// Pushes the obligations required for an alias (except inherent) to be WF
|
||||
/// into `self.out`.
|
||||
fn compute_alias_term(&mut self, data: ty::AliasTerm<'tcx>) {
|
||||
// A projection is well-formed if
|
||||
//
|
||||
// (a) its predicates hold (*)
|
||||
|
@ -699,7 +702,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
|||
}
|
||||
|
||||
ty::Alias(ty::Projection | ty::Opaque | ty::Weak, data) => {
|
||||
self.compute_alias(data);
|
||||
self.compute_alias_ty(data);
|
||||
return; // Subtree handled by compute_projection.
|
||||
}
|
||||
ty::Alias(ty::Inherent, data) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue