Skip to main content

rustc_next_trait_solver/solve/normalizes_to/
free_alias.rs

1//! Computes a normalizes-to (projection) goal for inherent associated types,
2//! `#![feature(lazy_type_alias)]` and `#![feature(type_alias_impl_trait)]`.
3//!
4//! Since a free alias is never ambiguous, this just computes the `type_of` of
5//! the alias and registers the where-clauses of the type alias.
6
7use rustc_type_ir::{self as ty, Interner, Unnormalized};
8
9use crate::delegate::SolverDelegate;
10use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult};
11
12impl<D, I> EvalCtxt<'_, D>
13where
14    D: SolverDelegate<Interner = I>,
15    I: Interner,
16{
17    pub(super) fn normalize_free_alias(
18        &mut self,
19        goal: Goal<I, ty::NormalizesTo<I>>,
20    ) -> QueryResult<I> {
21        let cx = self.cx();
22        let free_alias = goal.predicate.alias;
23
24        // Check where clauses
25        self.add_goals(
26            GoalSource::Misc,
27            cx.predicates_of(free_alias.def_id)
28                .iter_instantiated(cx, free_alias.args)
29                .map(Unnormalized::skip_norm_wip)
30                .map(|pred| goal.with(cx, pred)),
31        );
32
33        let actual = if free_alias.kind(cx).is_type() {
34            cx.type_of(free_alias.def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
35        } else {
36            cx.const_of_item(free_alias.def_id)
37                .instantiate(cx, free_alias.args)
38                .skip_norm_wip()
39                .into()
40        };
41
42        self.instantiate_normalizes_to_term(goal, actual);
43        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
44    }
45}