]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_infer/src/infer/projection.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / compiler / rustc_infer / src / infer / projection.rs
CommitLineData
c295e0f8
XL
1use rustc_middle::traits::ObligationCause;
2use rustc_middle::ty::{self, ToPredicate, Ty};
3
4use crate::traits::{Obligation, PredicateObligation};
5
6use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
7use super::InferCtxt;
8
2b03887a 9impl<'tcx> InferCtxt<'tcx> {
c295e0f8
XL
10 /// Instead of normalizing an associated type projection,
11 /// this function generates an inference variable and registers
12 /// an obligation that this inference variable must be the result
13 /// of the given projection. This allows us to proceed with projections
14 /// while they cannot be resolved yet due to missing information or
15 /// simply due to the lack of access to the trait resolution machinery.
16 pub fn infer_projection(
17 &self,
18 param_env: ty::ParamEnv<'tcx>,
19 projection_ty: ty::ProjectionTy<'tcx>,
20 cause: ObligationCause<'tcx>,
21 recursion_depth: usize,
22 obligations: &mut Vec<PredicateObligation<'tcx>>,
23 ) -> Ty<'tcx> {
24 let def_id = projection_ty.item_def_id;
25 let ty_var = self.next_ty_var(TypeVariableOrigin {
26 kind: TypeVariableOriginKind::NormalizeProjectionType,
27 span: self.tcx.def_span(def_id),
28 });
5099ac24
FG
29 let projection =
30 ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() });
c295e0f8
XL
31 let obligation = Obligation::with_depth(
32 cause,
33 recursion_depth,
34 param_env,
35 projection.to_predicate(self.tcx),
36 );
37 obligations.push(obligation);
38 ty_var
39 }
40}