change item_bounds query to return EarlyBinder; remove bound_item_bounds query
This commit is contained in:
parent
85eeaa9965
commit
fc942eed7f
9 changed files with 15 additions and 19 deletions
|
@ -99,12 +99,16 @@ pub(super) fn explicit_item_bounds(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> &'_ ty::List<ty::Predicate<'_>> {
|
pub(super) fn item_bounds(
|
||||||
tcx.mk_predicates(
|
tcx: TyCtxt<'_>,
|
||||||
|
def_id: DefId,
|
||||||
|
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
|
||||||
|
let bounds = tcx.mk_predicates(
|
||||||
util::elaborate_predicates(
|
util::elaborate_predicates(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
|
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
|
||||||
)
|
)
|
||||||
.map(|obligation| obligation.predicate),
|
.map(|obligation| obligation.predicate),
|
||||||
)
|
);
|
||||||
|
ty::EarlyBinder(bounds)
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> impl Iterator<Item = ty::Region<'tcx>> {
|
) -> impl Iterator<Item = ty::Region<'tcx>> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let bounds = tcx.bound_item_bounds(def_id);
|
let bounds = tcx.item_bounds(def_id);
|
||||||
trace!("{:#?}", bounds.0);
|
trace!("{:#?}", bounds.0);
|
||||||
bounds
|
bounds
|
||||||
.subst_iter(tcx, substs)
|
.subst_iter(tcx, substs)
|
||||||
|
|
|
@ -272,7 +272,7 @@ rustc_queries! {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Bounds from the parent (e.g. with nested impl trait) are not included.
|
/// Bounds from the parent (e.g. with nested impl trait) are not included.
|
||||||
query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
|
query item_bounds(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
|
||||||
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -659,13 +659,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
ty::EarlyBinder(self.explicit_item_bounds(def_id))
|
ty::EarlyBinder(self.explicit_item_bounds(def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bound_item_bounds(
|
|
||||||
self,
|
|
||||||
def_id: DefId,
|
|
||||||
) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
|
|
||||||
ty::EarlyBinder(self.item_bounds(def_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
|
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
|
||||||
ty::EarlyBinder(self.impl_subject(def_id))
|
ty::EarlyBinder(self.impl_subject(def_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1123,7 +1123,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
|
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
self.tcx.item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||||
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
||||||
// args tuple will always be substs[1]
|
// args tuple will always be substs[1]
|
||||||
|
|
|
@ -1375,7 +1375,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
|
||||||
// Check whether the self-type is itself a projection.
|
// Check whether the self-type is itself a projection.
|
||||||
// If so, extract what we know from the trait and try to come up with a good answer.
|
// If so, extract what we know from the trait and try to come up with a good answer.
|
||||||
let bounds = match *obligation.predicate.self_ty().kind() {
|
let bounds = match *obligation.predicate.self_ty().kind() {
|
||||||
ty::Alias(_, ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs),
|
ty::Alias(_, ref data) => tcx.item_bounds(data.def_id).subst(tcx, data.substs),
|
||||||
ty::Infer(ty::TyVar(_)) => {
|
ty::Infer(ty::TyVar(_)) => {
|
||||||
// If the self-type is an inference variable, then it MAY wind up
|
// If the self-type is an inference variable, then it MAY wind up
|
||||||
// being a projected type, so induce an ambiguity.
|
// being a projected type, so induce an ambiguity.
|
||||||
|
|
|
@ -160,8 +160,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
|
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
|
||||||
};
|
};
|
||||||
|
|
||||||
let candidate_predicate =
|
let candidate_predicate = tcx.item_bounds(def_id).map_bound(|i| i[idx]).subst(tcx, substs);
|
||||||
tcx.bound_item_bounds(def_id).map_bound(|i| i[idx]).subst(tcx, substs);
|
|
||||||
let candidate = candidate_predicate
|
let candidate = candidate_predicate
|
||||||
.to_opt_poly_trait_pred()
|
.to_opt_poly_trait_pred()
|
||||||
.expect("projection candidate is not a trait predicate")
|
.expect("projection candidate is not a trait predicate")
|
||||||
|
@ -510,7 +509,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
// This maybe belongs in wf, but that can't (doesn't) handle
|
// This maybe belongs in wf, but that can't (doesn't) handle
|
||||||
// higher-ranked things.
|
// higher-ranked things.
|
||||||
// Prevent, e.g., `dyn Iterator<Item = str>`.
|
// Prevent, e.g., `dyn Iterator<Item = str>`.
|
||||||
for bound in self.tcx().bound_item_bounds(assoc_type).transpose_iter() {
|
for bound in self.tcx().item_bounds(assoc_type).transpose_iter() {
|
||||||
let subst_bound =
|
let subst_bound =
|
||||||
if defs.count() == 0 {
|
if defs.count() == 0 {
|
||||||
bound.subst(tcx, trait_predicate.trait_ref.substs)
|
bound.subst(tcx, trait_predicate.trait_ref.substs)
|
||||||
|
|
|
@ -1604,7 +1604,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let bounds = tcx.bound_item_bounds(def_id).subst(tcx, substs);
|
let bounds = tcx.item_bounds(def_id).subst(tcx, substs);
|
||||||
|
|
||||||
// The bounds returned by `item_bounds` may contain duplicates after
|
// The bounds returned by `item_bounds` may contain duplicates after
|
||||||
// normalization, so try to deduplicate when possible to avoid
|
// normalization, so try to deduplicate when possible to avoid
|
||||||
|
|
|
@ -648,7 +648,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
|
||||||
},
|
},
|
||||||
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
|
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||||
sig_from_bounds(cx, ty, cx.tcx.bound_item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id))
|
sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id).subst_identity(), cx.tcx.opt_parent(def_id))
|
||||||
},
|
},
|
||||||
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
|
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
|
||||||
ty::Dynamic(bounds, _, _) => {
|
ty::Dynamic(bounds, _, _) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue