Skip to content

Commit dfb11a8

Browse files
committed
Add helper function to InferCtxt that generates inference vars for unresolved associated types
1 parent db1fb85 commit dfb11a8

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mod lub;
6464
pub mod nll_relate;
6565
pub mod opaque_types;
6666
pub mod outlives;
67+
mod projection;
6768
pub mod region_constraints;
6869
pub mod resolve;
6970
mod sub;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use rustc_middle::traits::ObligationCause;
2+
use rustc_middle::ty::{self, ToPredicate, Ty};
3+
4+
use crate::traits::{Obligation, PredicateObligation};
5+
6+
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
7+
use super::InferCtxt;
8+
9+
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10+
pub fn infer_projection(
11+
&self,
12+
param_env: ty::ParamEnv<'tcx>,
13+
projection_ty: ty::ProjectionTy<'tcx>,
14+
cause: ObligationCause<'tcx>,
15+
recursion_depth: usize,
16+
obligations: &mut Vec<PredicateObligation<'tcx>>,
17+
) -> Ty<'tcx> {
18+
let def_id = projection_ty.item_def_id;
19+
let ty_var = self.next_ty_var(TypeVariableOrigin {
20+
kind: TypeVariableOriginKind::NormalizeProjectionType,
21+
span: self.tcx.def_span(def_id),
22+
});
23+
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var });
24+
let obligation = Obligation::with_depth(
25+
cause,
26+
recursion_depth,
27+
param_env,
28+
projection.to_predicate(self.tcx),
29+
);
30+
obligations.push(obligation);
31+
ty_var
32+
}
33+
}

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
810810
// and a deferred predicate to resolve this when more type
811811
// information is available.
812812

813-
let tcx = selcx.infcx().tcx;
814-
let def_id = projection_ty.item_def_id;
815-
let ty_var = selcx.infcx().next_ty_var(TypeVariableOrigin {
816-
kind: TypeVariableOriginKind::NormalizeProjectionType,
817-
span: tcx.def_span(def_id),
818-
});
819-
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var });
820-
let obligation =
821-
Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate(tcx));
822-
obligations.push(obligation);
823-
ty_var
813+
selcx.infcx().infer_projection(param_env, projection_ty, cause, depth + 1, obligations)
824814
})
825815
}
826816

0 commit comments

Comments
 (0)