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 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 } if cx.is_type_const(def_id.into()) => {
41 let free = cx.const_of_item(def_id.into()).instantiate(cx, free_alias.args);
42 let free = self.normalize(GoalSource::Misc, goal.param_env, free)?;
43
44 free.into()
45 }
46 ty::AliasTermKind::FreeConst { .. } => {
47 return self.evaluate_const_and_instantiate_projection_term(
48 goal.param_env,
49 free_alias,
50 goal.predicate.term,
51 free_alias.expect_ct(),
52 );
53 }
54 kind => {
::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
kind));
}panic!("expected free alias, found {kind:?}"),
55 };
56
57 self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.projection_term, actual)?;
58 self.eq(goal.param_env, goal.predicate.term, actual)?;
59 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
60 }
61}