rustc_infer/infer/
projection.rs

1use rustc_middle::traits::ObligationCause;
2use rustc_middle::ty::{self, Ty};
3
4use super::InferCtxt;
5use crate::traits::{Obligation, PredicateObligations};
6
7impl<'tcx> InferCtxt<'tcx> {
8    /// Instead of normalizing an associated type projection,
9    /// this function generates an inference variable and registers
10    /// an obligation that this inference variable must be the result
11    /// of the given projection. This allows us to proceed with projections
12    /// while they cannot be resolved yet due to missing information or
13    /// simply due to the lack of access to the trait resolution machinery.
14    pub fn projection_ty_to_infer(
15        &self,
16        param_env: ty::ParamEnv<'tcx>,
17        projection_ty: ty::AliasTy<'tcx>,
18        cause: ObligationCause<'tcx>,
19        recursion_depth: usize,
20        obligations: &mut PredicateObligations<'tcx>,
21    ) -> Ty<'tcx> {
22        debug_assert!(!self.next_trait_solver());
23        let ty_var = self.next_ty_var(self.tcx.def_span(projection_ty.def_id));
24        let projection =
25            ty::PredicateKind::Clause(ty::ClauseKind::Projection(ty::ProjectionPredicate {
26                projection_term: projection_ty.into(),
27                term: ty_var.into(),
28            }));
29        let obligation =
30            Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection);
31        obligations.push(obligation);
32        ty_var
33    }
34}