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::ProjectionClause<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.clauses_of(free_alias.expect_free_def_id().into())
29 .iter_instantiated(cx, free_alias.args)
30 .map(Unnormalized::skip_norm_wip)
31 .map(|clause| goal.with(cx, clause)),
32 )?;
33
34 let actual = match free_alias.kind {
35 ty::AliasTermKind::FreeTy { def_id } => {
36 let free = cx.type_of(def_id.into()).instantiate(cx, free_alias.args);
37 let free = self.normalize(GoalSource::Misc, goal.param_env, free)?;
38 free.into()
39 }
40 ty::AliasTermKind::FreeConst { def_id }
41 if let Some(free) = cx.const_of_item(ty::AliasConstKind::Free { def_id }) =>
42 {
43 let free = free.instantiate(cx, free_alias.args);
44 let free = self.normalize(GoalSource::Misc, goal.param_env, free)?;
45
46 free.into()
47 }
48 ty::AliasTermKind::FreeConst { .. } => {
49 return self.evaluate_const_and_instantiate_projection_term(
50 goal.param_env,
51 free_alias,
52 goal.predicate.term,
53 free_alias.expect_ct(),
54 );
55 }
56 kind => {
::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
kind));
}panic!("expected free alias, found {kind:?}"),
57 };
58
59 self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.projection_term, actual)?;
60 self.eq(goal.param_env, goal.predicate.term, actual)?;
61 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
62 }
63}