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::solve::QueryResultOrRerunNonErased;
8use rustc_type_ir::{self as ty, Interner, Unnormalized};
9
10use crate::delegate::SolverDelegate;
11use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource};
12
13impl<D, I> EvalCtxt<'_, D>
14where
15    D: SolverDelegate<Interner = I>,
16    I: Interner,
17{
18    pub(super) fn normalize_free_alias(
19        &mut self,
20        goal: Goal<I, ty::NormalizesTo<I>>,
21    ) -> QueryResultOrRerunNonErased<I> {
22        let cx = self.cx();
23        let free_alias = goal.predicate.alias;
24
25        // Check where clauses
26        self.add_goals(
27            GoalSource::Misc,
28            cx.predicates_of(free_alias.def_id())
29                .iter_instantiated(cx, free_alias.args)
30                .map(Unnormalized::skip_norm_wip)
31                .map(|pred| goal.with(cx, pred)),
32        );
33
34        let actual = match free_alias.kind(cx) {
35            ty::AliasTermKind::FreeTy { def_id } => {
36                cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into()
37            }
38            ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => cx
39                .const_of_item(def_id.into())
40                .instantiate(cx, free_alias.args)
41                .skip_norm_wip()
42                .into(),
43            ty::AliasTermKind::FreeConst { .. } => {
44                return self.evaluate_const_and_instantiate_normalizes_to_term(
45                    goal,
46                    free_alias.expect_ct(cx),
47                );
48            }
49            kind => {
    ::core::panicking::panic_fmt(format_args!("expected free alias, found {0:?}",
            kind));
}panic!("expected free alias, found {kind:?}"),
50        };
51
52        self.instantiate_normalizes_to_term(goal, actual);
53        self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
54    }
55}