2021-08-10 11:12:11 +00:00
|
|
|
use rustc_middle::traits::ObligationCause;
|
|
|
|
use rustc_middle::ty::{self, ToPredicate, Ty};
|
|
|
|
|
|
|
|
use crate::traits::{Obligation, PredicateObligation};
|
|
|
|
|
|
|
|
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
|
|
|
use super::InferCtxt;
|
|
|
|
|
|
|
|
impl<'a, 'tcx> InferCtxt<'a, '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.
|
2021-08-10 11:12:11 +00:00
|
|
|
pub fn infer_projection(
|
|
|
|
&self,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
projection_ty: ty::ProjectionTy<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
recursion_depth: usize,
|
|
|
|
obligations: &mut Vec<PredicateObligation<'tcx>>,
|
|
|
|
) -> Ty<'tcx> {
|
|
|
|
let def_id = projection_ty.item_def_id;
|
|
|
|
let ty_var = self.next_ty_var(TypeVariableOrigin {
|
|
|
|
kind: TypeVariableOriginKind::NormalizeProjectionType,
|
|
|
|
span: self.tcx.def_span(def_id),
|
|
|
|
});
|
2022-01-08 09:28:12 +00:00
|
|
|
let projection =
|
|
|
|
ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() });
|
2021-08-10 11:12:11 +00:00
|
|
|
let obligation = Obligation::with_depth(
|
|
|
|
cause,
|
|
|
|
recursion_depth,
|
|
|
|
param_env,
|
|
|
|
projection.to_predicate(self.tcx),
|
|
|
|
);
|
|
|
|
obligations.push(obligation);
|
|
|
|
ty_var
|
|
|
|
}
|
|
|
|
}
|