Rename projection_predicates to item_bounds

This commit is contained in:
Matthew Jasper 2020-06-23 17:57:24 +01:00
parent 5ded394553
commit 0eb87ed55f
6 changed files with 21 additions and 32 deletions

View File

@ -328,8 +328,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
assoc_item_def_id: DefId,
) -> impl Iterator<Item = ty::Region<'tcx>> {
let tcx = self.tcx;
let predicates = tcx.projection_predicates(assoc_item_def_id);
predicates
let bounds = tcx.item_bounds(assoc_item_def_id);
bounds
.into_iter()
.filter_map(|p| p.to_opt_type_outlives())
.filter_map(|p| p.no_bound_vars())

View File

@ -156,7 +156,7 @@ rustc_queries! {
cache_on_disk_if { key.is_local() }
}
/// Returns the list of predicates that can be used for
/// Returns the list of bounds that can be used for
/// `SelectionCandidate::ProjectionCandidate` and
/// `ProjectionTyCandidate::TraitDef`.
/// Specifically this is the bounds (equivalent to) those
@ -169,7 +169,7 @@ rustc_queries! {
/// ^^^^^^^^^^^^^^^
///
/// `key` is the `DefId` of the associated type or opaque type.
query projection_predicates(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
desc { |tcx| "finding projection predicates for `{}`", tcx.def_path_str(key) }
}

View File

@ -909,10 +909,8 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
// 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.
let bounds = match *obligation_trait_ref.self_ty().kind() {
ty::Projection(ref data) => {
tcx.projection_predicates(data.item_def_id).subst(tcx, data.substs)
}
ty::Opaque(def_id, substs) => tcx.projection_predicates(def_id).subst(tcx, substs),
ty::Projection(ref data) => tcx.item_bounds(data.item_def_id).subst(tcx, data.substs),
ty::Opaque(def_id, substs) => tcx.item_bounds(def_id).subst(tcx, substs),
ty::Infer(ty::TyVar(_)) => {
// If the self-type is an inference variable, then it MAY wind up
// being a projected type, so induce an ambiguity.

View File

@ -1171,10 +1171,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let tcx = self.infcx.tcx;
let predicates = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
ty::Projection(ref data) => {
tcx.projection_predicates(data.item_def_id).subst(tcx, data.substs)
}
ty::Opaque(def_id, substs) => tcx.projection_predicates(def_id).subst(tcx, substs),
ty::Projection(ref data) => tcx.item_bounds(data.item_def_id).subst(tcx, data.substs),
ty::Opaque(def_id, substs) => tcx.item_bounds(def_id).subst(tcx, substs),
_ => {
span_bug!(
obligation.cause.span,

View File

@ -500,7 +500,7 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
/// simplify checking that these bounds are met in impls. This means that
/// a bound such as `for<'b> <Self as X<'b>>::U: Clone` can't be used, as in
/// `hr-associated-type-bound-1.rs`.
fn associated_type_projection_predicates(
fn associated_type_bounds(
tcx: TyCtxt<'_>,
assoc_item_def_id: DefId,
) -> &'_ ty::List<ty::Predicate<'_>> {
@ -545,21 +545,14 @@ fn associated_type_projection_predicates(
});
let result = tcx.mk_predicates(predicates);
debug!(
"associated_type_projection_predicates({}) = {:?}",
tcx.def_path_str(assoc_item_def_id),
result
);
debug!("associated_type_bounds({}) = {:?}", tcx.def_path_str(assoc_item_def_id), result);
result
}
/// Opaque types don't have the same issues as associated types: the only
/// predicates on an opaque type (excluding those it inherits from its parent
/// item) should be of the form we're expecting.
fn opaque_type_projection_predicates(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> &'_ ty::List<ty::Predicate<'_>> {
fn opaque_type_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> &'_ ty::List<ty::Predicate<'_>> {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
let bounds = tcx.predicates_of(def_id);
@ -607,15 +600,15 @@ fn opaque_type_projection_predicates(
});
let result = tcx.mk_predicates(filtered_predicates);
debug!("opaque_type_projection_predicates({}) = {:?}", tcx.def_path_str(def_id), result);
debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(def_id), result);
result
}
fn projection_predicates(tcx: TyCtxt<'_>, def_id: DefId) -> &'_ ty::List<ty::Predicate<'_>> {
fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> &'_ ty::List<ty::Predicate<'_>> {
match tcx.def_kind(def_id) {
DefKind::AssocTy => associated_type_projection_predicates(tcx, def_id),
DefKind::OpaqueTy => opaque_type_projection_predicates(tcx, def_id),
k => bug!("projection_predicates called on {}", k.descr(def_id)),
DefKind::AssocTy => associated_type_bounds(tcx, def_id),
DefKind::OpaqueTy => opaque_type_bounds(tcx, def_id),
k => bug!("item_bounds called on {}", k.descr(def_id)),
}
}
@ -636,7 +629,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
instance_def_size_estimate,
issue33140_self_ty,
impl_defaultness,
projection_predicates,
item_bounds,
..*providers
};
}

View File

@ -1052,7 +1052,7 @@ crate fn compare_ty_impl<'tcx>(
compare_type_predicate_entailment(tcx, impl_ty, impl_ty_span, trait_ty, impl_trait_ref)?;
compare_projection_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref)
check_type_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref)
})();
}
@ -1170,7 +1170,7 @@ fn compare_type_predicate_entailment<'tcx>(
/// For default associated types the normalization is not possible (the value
/// from the impl could be overridden). We also can't normalize generic
/// associated types (yet) because they contain bound parameters.
fn compare_projection_bounds<'tcx>(
fn check_type_bounds<'tcx>(
tcx: TyCtxt<'tcx>,
trait_ty: &ty::AssocItem,
impl_ty: &ty::AssocItem,
@ -1237,8 +1237,8 @@ fn compare_projection_bounds<'tcx>(
ObligationCauseCode::ItemObligation(trait_ty.def_id),
);
let predicates = tcx.projection_predicates(trait_ty.def_id);
debug!("compare_projection_bounds: projection_predicates={:?}", predicates);
let predicates = tcx.item_bounds(trait_ty.def_id);
debug!("check_type_bounds: item_bounds={:?}", predicates);
for predicate in predicates {
let concrete_ty_predicate = predicate.subst(tcx, rebased_substs);