2021-08-10 11:12:11 +00:00
|
|
|
use rustc_middle::traits::ObligationCause;
|
2022-11-09 10:49:28 +00:00
|
|
|
use rustc_middle::ty::{self, Ty};
|
2021-08-10 11:12:11 +00:00
|
|
|
|
|
|
|
|
use super::InferCtxt;
|
2024-10-09 01:02:55 +01:00
|
|
|
use crate::traits::{Obligation, PredicateObligations};
|
2021-08-10 11:12:11 +00:00
|
|
|
|
2022-09-09 13:01:06 -05:00
|
|
|
impl<'tcx> InferCtxt<'tcx> {
|
2021-09-18 09:34:06 +02:00
|
|
|
/// Instead of normalizing an associated type projection,
|
|
|
|
|
/// this function generates an inference variable and registers
|
|
|
|
|
/// an obligation that this inference variable must be the result
|
|
|
|
|
/// of the given projection. This allows us to proceed with projections
|
|
|
|
|
/// while they cannot be resolved yet due to missing information or
|
|
|
|
|
/// simply due to the lack of access to the trait resolution machinery.
|
2024-05-13 10:00:38 -04:00
|
|
|
pub fn projection_ty_to_infer(
|
2021-08-10 11:12:11 +00:00
|
|
|
&self,
|
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
2022-11-26 21:32:01 +00:00
|
|
|
projection_ty: ty::AliasTy<'tcx>,
|
2021-08-10 11:12:11 +00:00
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
|
recursion_depth: usize,
|
2024-10-09 01:02:55 +01:00
|
|
|
obligations: &mut PredicateObligations<'tcx>,
|
2021-08-10 11:12:11 +00:00
|
|
|
) -> Ty<'tcx> {
|
2023-07-04 10:06:39 +02:00
|
|
|
debug_assert!(!self.next_trait_solver());
|
2024-06-07 11:51:03 -04:00
|
|
|
let ty_var = self.next_ty_var(self.tcx.def_span(projection_ty.def_id));
|
|
|
|
|
let projection =
|
|
|
|
|
ty::PredicateKind::Clause(ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
|
|
|
|
projection_term: projection_ty.into(),
|
|
|
|
|
term: ty_var.into(),
|
|
|
|
|
}));
|
2023-07-04 10:06:39 +02:00
|
|
|
let obligation =
|
|
|
|
|
Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection);
|
|
|
|
|
obligations.push(obligation);
|
|
|
|
|
ty_var
|
2021-08-10 11:12:11 +00:00
|
|
|
}
|
|
|
|
|
}
|