Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper function to
InferCtxt
that generates inference vars for …
…unresolved associated types
- Loading branch information
Showing
3 changed files
with
35 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters