2023-12-18 07:49:46 +01:00
|
|
|
use crate::solve::GoalSource;
|
|
|
|
|
|
2023-12-07 18:20:27 +01:00
|
|
|
use super::EvalCtxt;
|
|
|
|
|
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
|
|
|
|
|
use rustc_middle::ty::{self, ProjectionPredicate};
|
|
|
|
|
|
|
|
|
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|
|
|
|
#[instrument(level = "debug", skip(self), ret)]
|
|
|
|
|
pub(super) fn compute_projection_goal(
|
|
|
|
|
&mut self,
|
|
|
|
|
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
|
|
|
|
|
) -> QueryResult<'tcx> {
|
2023-12-13 14:11:09 +00:00
|
|
|
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(),
|
|
|
|
|
};
|
2023-12-18 07:49:46 +01:00
|
|
|
let goal = goal.with(
|
2023-12-13 14:11:09 +00:00
|
|
|
tcx,
|
|
|
|
|
ty::PredicateKind::AliasRelate(
|
|
|
|
|
projection_term,
|
|
|
|
|
goal.predicate.term,
|
|
|
|
|
ty::AliasRelationDirection::Equate,
|
|
|
|
|
),
|
2023-12-18 07:49:46 +01:00
|
|
|
);
|
|
|
|
|
self.add_goal(GoalSource::Misc, goal);
|
2023-12-13 14:11:09 +00:00
|
|
|
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
2023-12-07 18:20:27 +01:00
|
|
|
}
|
|
|
|
|
}
|