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_type(
19        &mut self,
20        goal: Goal<I, ty::NormalizesTo<I>>,
21    ) -> QueryResult<I> {
22        let cx = self.cx();
23        let inherent = goal.predicate.alias.expect_ty(cx);
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 not 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        self.add_goals(
45            GoalSource::Misc,
46            cx.predicates_of(inherent.def_id)
47                .iter_instantiated(cx, inherent_args)
48                .map(|pred| goal.with(cx, pred)),
49        );
50
51        let normalized = cx.type_of(inherent.def_id).instantiate(cx, inherent_args);
52        self.instantiate_normalizes_to_term(goal, normalized.into());
53        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
54    }
55}