rustc_next_trait_solver/solve/project_goals/
free_alias.rs1use rustc_type_ir::solve::QueryResultOrRerunNonErased;
8use rustc_type_ir::{self as ty, Interner, Unnormalized};
9
10use crate::delegate::SolverDelegate;
11use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource};
12
13impl<D, I> EvalCtxt<'_, D>
14where
15 D: SolverDelegate<Interner = I>,
16 I: Interner,
17{
18 pub(super) fn normalize_free_alias(
19 &mut self,
20 goal: Goal<I, ty::ProjectionPredicate<I>>,
21 ) -> QueryResultOrRerunNonErased<I> {
22 let cx = self.cx();
23 let free_alias = goal.predicate.projection_term;
24
25 self.add_goals(
27 GoalSource::Misc,
28 cx.predicates_of(free_alias.expect_free_def_id().into())
29 .iter_instantiated(cx, free_alias.args)
30 .map(Unnormalized::skip_norm_wip)
31 .map(|pred| goal.with(cx, pred)),
32 );
33
34 let actual = match free_alias.kind {
35 ty::AliasTermKind::FreeTy { def_id } => {
36 cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into()
37 }
38 ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => cx
39 .const_of_item(def_id.into())
40 .instantiate(cx, free_alias.args)
41 .skip_norm_wip()
42 .into(),
43 ty::AliasTermKind::FreeConst { .. } => {
44 return self.evaluate_const_and_instantiate_projection_term(
45 goal.param_env,
46 free_alias,
47 goal.predicate.term,
48 free_alias.expect_ct(),
49 );
50 }
51 kind => {
::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
kind));
}panic!("expected free alias, found {kind:?}"),
52 };
53
54 self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.projection_term, actual);
55 self.eq(goal.param_env, goal.predicate.term, actual)?;
56 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
57 }
58}