Skip to content

Commit

Permalink
Add helper function to InferCtxt that generates inference vars for …
Browse files Browse the repository at this point in the history
…unresolved associated types
  • Loading branch information
oli-obk committed Sep 20, 2021
1 parent db1fb85 commit dfb11a8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Expand Up @@ -64,6 +64,7 @@ mod lub;
pub mod nll_relate;
pub mod opaque_types;
pub mod outlives;
mod projection;
pub mod region_constraints;
pub mod resolve;
mod sub;
Expand Down
33 changes: 33 additions & 0 deletions compiler/rustc_infer/src/infer/projection.rs
@@ -0,0 +1,33 @@
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> {
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),
});
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var });
let obligation = Obligation::with_depth(
cause,
recursion_depth,
param_env,
projection.to_predicate(self.tcx),
);
obligations.push(obligation);
ty_var
}
}
12 changes: 1 addition & 11 deletions compiler/rustc_trait_selection/src/traits/project.rs
Expand Up @@ -810,17 +810,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
// and a deferred predicate to resolve this when more type
// information is available.

let tcx = selcx.infcx().tcx;
let def_id = projection_ty.item_def_id;
let ty_var = selcx.infcx().next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::NormalizeProjectionType,
span: tcx.def_span(def_id),
});
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var });
let obligation =
Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate(tcx));
obligations.push(obligation);
ty_var
selcx.infcx().infer_projection(param_env, projection_ty, cause, depth + 1, obligations)
})
}

Expand Down

0 comments on commit dfb11a8

Please sign in to comment.