rustc_next_trait_solver/solve/normalizes_to/
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::NormalizesTo<I>>,
22 def_id: I::InherentAssocTermId,
23 ) -> QueryResultOrRerunNonErased<I> {
24 let cx = self.cx();
25 let inherent = goal.predicate.alias;
26
27 let impl_def_id = cx.inherent_alias_term_parent(def_id);
28 let impl_args = self.fresh_args_for_item(impl_def_id.into());
29
30 self.eq(
32 goal.param_env,
33 inherent.self_ty(),
34 cx.type_of(impl_def_id.into()).instantiate(cx, impl_args).skip_norm_wip(),
35 )?;
36
37 let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, cx);
39
40 self.add_goals(
50 GoalSource::Misc,
51 cx.predicates_of(def_id.into())
52 .iter_instantiated(cx, inherent_args)
53 .map(Unnormalized::skip_norm_wip)
54 .map(|pred| goal.with(cx, pred)),
55 );
56
57 let normalized = match inherent.kind(cx) {
58 ty::AliasTermKind::InherentTy { def_id } => {
59 cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
60 }
61 ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => cx
62 .const_of_item(def_id.into())
63 .instantiate(cx, inherent_args)
64 .skip_norm_wip()
65 .into(),
66 ty::AliasTermKind::InherentConst { .. } => {
67 {
::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");
74 }
75 kind => {
::core::panicking::panic_fmt(format_args!("expected inherent alias, found {0:?}",
kind));
}panic!("expected inherent alias, found {kind:?}"),
76 };
77 self.instantiate_normalizes_to_term(goal, normalized);
78 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
79 }
80}