rustc_next_trait_solver/solve/project_goals/
inherent.rs1use rustc_type_ir::solve::QueryResultOrRerunNonErased;
9use rustc_type_ir::{self as ty, Interner, Unnormalized};
10
11use crate::delegate::SolverDelegate;
12use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource};
13
14impl<D, I> EvalCtxt<'_, D>
15where
16 D: SolverDelegate<Interner = I>,
17 I: Interner,
18{
19 pub(super) fn normalize_inherent_associated_term(
20 &mut self,
21 goal: Goal<I, ty::ProjectionPredicate<I>>,
22 ) -> QueryResultOrRerunNonErased<I> {
23 let cx = self.cx();
24 let inherent = goal.predicate.projection_term;
25 let def_id = inherent.expect_inherent_def_id();
26 let impl_def_id = cx.inherent_alias_term_parent(def_id);
27 let impl_args = self.fresh_args_for_item(impl_def_id.into());
28
29 self.eq(
31 goal.param_env,
32 inherent.self_ty(),
33 cx.type_of(impl_def_id.into()).instantiate(cx, impl_args).skip_norm_wip(),
34 )?;
35
36 let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, cx);
38
39 self.add_goals(
49 GoalSource::Misc,
50 cx.predicates_of(def_id.into())
51 .iter_instantiated(cx, inherent_args)
52 .map(Unnormalized::skip_norm_wip)
53 .map(|pred| goal.with(cx, pred)),
54 );
55
56 let normalized: I::Term = match inherent.kind {
57 ty::AliasTermKind::InherentTy { def_id } => {
58 cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
59 }
60 ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => cx
61 .const_of_item(def_id.into())
62 .instantiate(cx, inherent_args)
63 .skip_norm_wip()
64 .into(),
65 ty::AliasTermKind::InherentConst { .. } => {
66 {
::core::panicking::panic_fmt(format_args!("References to inherent associated consts should have been blocked"));
};panic!("References to inherent associated consts should have been blocked");
73 }
74 kind => {
::core::panicking::panic_fmt(format_args!("expected inherent alias, found {0:?}",
kind));
}panic!("expected inherent alias, found {kind:?}"),
75 };
76
77 self.push_const_arg_has_type_goal(
78 goal.param_env,
79 goal.predicate.projection_term,
80 normalized,
81 );
82 self.eq(goal.param_env, goal.predicate.term, normalized)?;
83 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
84 }
85}