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};
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(|pred| goal.with(cx, pred)),
30        );
31
32        let actual = if free_alias.kind(cx).is_type() {
33            cx.type_of(free_alias.def_id).instantiate(cx, free_alias.args)
34        } else {
35            // FIXME(mgca): once const items are actual aliases defined as equal to type system consts
36            // this should instead return that.
37            panic!("normalizing free const aliases in the type system is unsupported");
38        };
39
40        self.instantiate_normalizes_to_term(goal, actual.into());
41        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
42    }
43}