rustc_next_trait_solver/solve/normalizes_to/inherent.rs
1//! Computes a normalizes-to (projection) goal for inherent associated types,
2//! `#![feature(inherent_associated_type)]`. Since HIR ty lowering already determines
3//! which impl the IAT is being projected from, we just:
4//! 1. instantiate generic parameters,
5//! 2. equate the self type, and
6//! 3. instantiate and register where clauses.
7
8use rustc_type_ir::{self as ty, Interner};
9
10use crate::delegate::SolverDelegate;
11use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult};
12
13impl<D, I> EvalCtxt<'_, D>
14where
15 D: SolverDelegate<Interner = I>,
16 I: Interner,
17{
18 pub(super) fn normalize_inherent_associated_term(
19 &mut self,
20 goal: Goal<I, ty::NormalizesTo<I>>,
21 ) -> QueryResult<I> {
22 let cx = self.cx();
23 let inherent = goal.predicate.alias;
24
25 let impl_def_id = cx.parent(inherent.def_id);
26 let impl_args = self.fresh_args_for_item(impl_def_id);
27
28 // Equate impl header and add impl where clauses
29 self.eq(
30 goal.param_env,
31 inherent.self_ty(),
32 cx.type_of(impl_def_id).instantiate(cx, impl_args),
33 )?;
34
35 // Equate IAT with the RHS of the project goal
36 let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, cx);
37
38 // Check both where clauses on the impl and IAT
39 //
40 // FIXME(-Znext-solver=coinductive): I think this should be split
41 // and we tag the impl bounds with `GoalSource::ImplWhereBound`?
42 // Right now this includes both the impl and the assoc item where bounds,
43 // and I don't think the assoc item where-bounds are allowed to be coinductive.
44 //
45 // Projecting to the IAT also "steps out the impl contructor", so we would have
46 // to be very careful when changing the impl where-clauses to be productive.
47 self.add_goals(
48 GoalSource::Misc,
49 cx.predicates_of(inherent.def_id)
50 .iter_instantiated(cx, inherent_args)
51 .map(|pred| goal.with(cx, pred)),
52 );
53
54 let normalized = if inherent.kind(cx).is_type() {
55 cx.type_of(inherent.def_id).instantiate(cx, inherent_args).into()
56 } else {
57 // FIXME(mgca): Properly handle IACs in the type system
58 panic!("normalizing inherent associated consts in the type system is unsupported");
59 };
60 self.instantiate_normalizes_to_term(goal, normalized);
61 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
62 }
63}