add projection_ty_from_predicates query
This commit is contained in:
parent
8ee206a80d
commit
7cfcefd1fb
5 changed files with 31 additions and 32 deletions
|
@ -1574,17 +1574,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.def_id;
|
.def_id;
|
||||||
|
|
||||||
let mut projection_ty = None;
|
let projection_ty = self.tcx.projection_ty_from_predicates((def_id, item_def_id));
|
||||||
for (predicate, _) in self.tcx.predicates_of(def_id).predicates {
|
|
||||||
if let ty::PredicateAtom::Projection(projection_predicate) =
|
|
||||||
predicate.skip_binders()
|
|
||||||
{
|
|
||||||
if item_def_id == projection_predicate.projection_ty.item_def_id {
|
|
||||||
projection_ty = Some(projection_predicate.projection_ty);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(projection_ty) = projection_ty {
|
if let Some(projection_ty) = projection_ty {
|
||||||
let projection_query = self.canonicalize_query(
|
let projection_query = self.canonicalize_query(
|
||||||
&ParamEnvAnd { param_env: self.tcx.param_env(def_id), value: projection_ty },
|
&ParamEnvAnd { param_env: self.tcx.param_env(def_id), value: projection_ty },
|
||||||
|
|
|
@ -173,6 +173,10 @@ rustc_queries! {
|
||||||
desc { |tcx| "finding projection predicates for `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "finding projection predicates for `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
|
||||||
|
desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
|
||||||
|
}
|
||||||
|
|
||||||
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
|
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
|
||||||
desc { "looking up the native libraries of a linked crate" }
|
desc { "looking up the native libraries of a linked crate" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1523,15 +1523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let item_def_id =
|
let item_def_id =
|
||||||
self.tcx.associated_items(future_trait).in_definition_order().next().unwrap().def_id;
|
self.tcx.associated_items(future_trait).in_definition_order().next().unwrap().def_id;
|
||||||
|
|
||||||
let mut projection_ty = None;
|
let projection_ty = self.tcx.projection_ty_from_predicates((def_id, item_def_id));
|
||||||
for (predicate, _) in self.tcx.predicates_of(def_id).predicates {
|
|
||||||
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
|
|
||||||
if item_def_id == projection_predicate.projection_ty.item_def_id {
|
|
||||||
projection_ty = Some(projection_predicate.projection_ty);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug!("suggest_await_on_field_access: projection_ty={:?}", projection_ty);
|
debug!("suggest_await_on_field_access: projection_ty={:?}", projection_ty);
|
||||||
|
|
||||||
let cause = self.misc(expr.span);
|
let cause = self.misc(expr.span);
|
||||||
|
|
|
@ -870,7 +870,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
call: &hir::Expr<'_>,
|
call: &hir::Expr<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
if let ty::Opaque(def_id, _substs) = ty.kind {
|
if let ty::Opaque(def_id, _) = ty.kind {
|
||||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||||
// Future::Output
|
// Future::Output
|
||||||
let item_def_id = self
|
let item_def_id = self
|
||||||
|
@ -881,17 +881,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.def_id;
|
.def_id;
|
||||||
|
|
||||||
let mut projection_ty = None;
|
let projection_ty = self.tcx.projection_ty_from_predicates((def_id, item_def_id));
|
||||||
for (predicate, _) in self.tcx.predicates_of(def_id).predicates {
|
|
||||||
if let ty::PredicateAtom::Projection(projection_predicate) =
|
|
||||||
predicate.skip_binders()
|
|
||||||
{
|
|
||||||
if item_def_id == projection_predicate.projection_ty.item_def_id {
|
|
||||||
projection_ty = Some(projection_predicate.projection_ty);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let cause = self.misc(span);
|
let cause = self.misc(span);
|
||||||
let mut selcx = SelectionContext::new(&self.infcx);
|
let mut selcx = SelectionContext::new(&self.infcx);
|
||||||
let mut obligations = vec![];
|
let mut obligations = vec![];
|
||||||
|
|
|
@ -70,6 +70,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
generics_of,
|
generics_of,
|
||||||
predicates_of,
|
predicates_of,
|
||||||
predicates_defined_on,
|
predicates_defined_on,
|
||||||
|
projection_ty_from_predicates,
|
||||||
explicit_predicates_of,
|
explicit_predicates_of,
|
||||||
super_predicates_of,
|
super_predicates_of,
|
||||||
type_param_predicates,
|
type_param_predicates,
|
||||||
|
@ -2051,6 +2052,28 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn projection_ty_from_predicates(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
key: (
|
||||||
|
// ty_def_id
|
||||||
|
DefId,
|
||||||
|
// def_id of `N` in `<T as Trait>::N`
|
||||||
|
DefId,
|
||||||
|
),
|
||||||
|
) -> Option<ty::ProjectionTy<'tcx>> {
|
||||||
|
let (ty_def_id, item_def_id) = key;
|
||||||
|
let mut projection_ty = None;
|
||||||
|
for (predicate, _) in tcx.predicates_of(ty_def_id).predicates {
|
||||||
|
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
|
||||||
|
if item_def_id == projection_predicate.projection_ty.item_def_id {
|
||||||
|
projection_ty = Some(projection_predicate.projection_ty);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
projection_ty
|
||||||
|
}
|
||||||
|
|
||||||
fn trait_associated_item_predicates(
|
fn trait_associated_item_predicates(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue