mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Rename things to reflect that they're not item specific
This commit is contained in:
parent
20a83144b2
commit
fef2f5b815
@ -1040,7 +1040,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
|
||||
/// Convert the bounds in `ast_bounds` that refer to traits which define an associated type
|
||||
/// named `assoc_name` into ty::Bounds. Ignore the rest.
|
||||
pub(crate) fn compute_bounds_that_match_assoc_type(
|
||||
pub(crate) fn compute_bounds_that_match_assoc_item(
|
||||
&self,
|
||||
param_ty: Ty<'tcx>,
|
||||
ast_bounds: &[hir::GenericBound<'_>],
|
||||
@ -1051,7 +1051,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
for ast_bound in ast_bounds {
|
||||
if let Some(trait_ref) = ast_bound.trait_ref()
|
||||
&& let Some(trait_did) = trait_ref.trait_def_id()
|
||||
&& self.tcx().trait_may_define_assoc_type(trait_did, assoc_name)
|
||||
&& self.tcx().trait_may_define_assoc_item(trait_did, assoc_name)
|
||||
{
|
||||
result.push(ast_bound.clone());
|
||||
}
|
||||
@ -1923,7 +1923,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let param_name = tcx.hir().ty_param_name(ty_param_def_id);
|
||||
self.one_bound_for_assoc_type(
|
||||
|| {
|
||||
traits::transitive_bounds_that_define_assoc_type(
|
||||
traits::transitive_bounds_that_define_assoc_item(
|
||||
tcx,
|
||||
predicates.iter().filter_map(|(p, _)| {
|
||||
Some(p.to_opt_poly_trait_pred()?.map_bound(|t| t.trait_ref))
|
||||
|
@ -64,8 +64,8 @@ pub fn provide(providers: &mut Providers) {
|
||||
explicit_predicates_of: predicates_of::explicit_predicates_of,
|
||||
super_predicates_of: predicates_of::super_predicates_of,
|
||||
implied_predicates_of: predicates_of::implied_predicates_of,
|
||||
super_predicates_that_define_assoc_type:
|
||||
predicates_of::super_predicates_that_define_assoc_type,
|
||||
super_predicates_that_define_assoc_item:
|
||||
predicates_of::super_predicates_that_define_assoc_item,
|
||||
trait_explicit_predicates_and_bounds: predicates_of::trait_explicit_predicates_and_bounds,
|
||||
type_param_predicates: predicates_of::type_param_predicates,
|
||||
trait_def,
|
||||
|
@ -565,7 +565,7 @@ pub(super) fn super_predicates_of(
|
||||
implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
|
||||
}
|
||||
|
||||
pub(super) fn super_predicates_that_define_assoc_type(
|
||||
pub(super) fn super_predicates_that_define_assoc_item(
|
||||
tcx: TyCtxt<'_>,
|
||||
(trait_def_id, assoc_name): (DefId, Ident),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
@ -640,7 +640,7 @@ pub(super) fn implied_predicates_with_filter(
|
||||
),
|
||||
PredicateFilter::SelfThatDefines(assoc_name) => (
|
||||
// Convert the bounds that follow the colon (or equal) that reference the associated name
|
||||
icx.astconv().compute_bounds_that_match_assoc_type(self_param_ty, bounds, assoc_name),
|
||||
icx.astconv().compute_bounds_that_match_assoc_item(self_param_ty, bounds, assoc_name),
|
||||
// Include where clause bounds for `Self` that reference the associated name
|
||||
icx.type_parameter_bounds_in_generics(
|
||||
generics,
|
||||
@ -819,7 +819,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||
hir::GenericBound::Trait(poly_trait_ref, _) => {
|
||||
let trait_ref = &poly_trait_ref.trait_ref;
|
||||
if let Some(trait_did) = trait_ref.trait_def_id() {
|
||||
self.tcx.trait_may_define_assoc_type(trait_did, assoc_name)
|
||||
self.tcx.trait_may_define_assoc_item(trait_did, assoc_name)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -1728,7 +1728,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
assoc_name: Ident,
|
||||
assoc_kind: ty::AssocKind,
|
||||
) -> Option<(Vec<ty::BoundVariableKind>, &'tcx ty::AssocItem)> {
|
||||
let trait_defines_associated_type_named = |trait_def_id: DefId| {
|
||||
let trait_defines_associated_item_named = |trait_def_id: DefId| {
|
||||
tcx.associated_items(trait_def_id).find_by_name_and_kind(
|
||||
tcx,
|
||||
assoc_name,
|
||||
@ -1752,10 +1752,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
_ => break None,
|
||||
}
|
||||
|
||||
if let Some(assoc_item) = trait_defines_associated_type_named(def_id) {
|
||||
if let Some(assoc_item) = trait_defines_associated_item_named(def_id) {
|
||||
break Some((bound_vars.into_iter().collect(), assoc_item));
|
||||
}
|
||||
let predicates = tcx.super_predicates_that_define_assoc_type((def_id, assoc_name));
|
||||
let predicates = tcx.super_predicates_that_define_assoc_item((def_id, assoc_name));
|
||||
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
|
||||
let bound_predicate = pred.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
|
@ -376,11 +376,11 @@ pub fn transitive_bounds<'tcx>(
|
||||
}
|
||||
|
||||
/// A specialized variant of `elaborate` that only elaborates trait references that may
|
||||
/// define the given associated type `assoc_name`. It uses the
|
||||
/// `super_predicates_that_define_assoc_type` query to avoid enumerating super-predicates that
|
||||
/// define the given associated item with the name `assoc_name`. It uses the
|
||||
/// `super_predicates_that_define_assoc_item` query to avoid enumerating super-predicates that
|
||||
/// aren't related to `assoc_item`. This is used when resolving types like `Self::Item` or
|
||||
/// `T::Item` and helps to avoid cycle errors (see e.g. #35237).
|
||||
pub fn transitive_bounds_that_define_assoc_type<'tcx>(
|
||||
pub fn transitive_bounds_that_define_assoc_item<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||
assoc_name: Ident,
|
||||
@ -393,7 +393,7 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
|
||||
let anon_trait_ref = tcx.anonymize_bound_vars(trait_ref);
|
||||
if visited.insert(anon_trait_ref) {
|
||||
let super_predicates =
|
||||
tcx.super_predicates_that_define_assoc_type((trait_ref.def_id(), assoc_name));
|
||||
tcx.super_predicates_that_define_assoc_item((trait_ref.def_id(), assoc_name));
|
||||
for (super_predicate, _) in super_predicates.predicates {
|
||||
let subst_predicate = super_predicate.subst_supertrait(tcx, &trait_ref);
|
||||
if let Some(binder) = subst_predicate.to_opt_poly_trait_pred() {
|
||||
|
@ -569,7 +569,7 @@ rustc_queries! {
|
||||
/// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
|
||||
/// subset of super-predicates that reference traits that define the given associated type.
|
||||
/// This is used to avoid cycles in resolving types like `T::Item`.
|
||||
query super_predicates_that_define_assoc_type(key: (DefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
query super_predicates_that_define_assoc_item(key: (DefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
desc { |tcx| "computing the super traits of `{}` with associated type name `{}`",
|
||||
tcx.def_path_str(key.0),
|
||||
key.1
|
||||
|
@ -1567,16 +1567,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
|
||||
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
|
||||
pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Ident) -> bool {
|
||||
pub fn trait_may_define_assoc_item(self, trait_def_id: DefId, assoc_name: Ident) -> bool {
|
||||
self.super_traits_of(trait_def_id).any(|trait_did| {
|
||||
self.associated_items(trait_did)
|
||||
.find_by_name_and_kinds(
|
||||
self,
|
||||
assoc_name,
|
||||
&[ty::AssocKind::Type, ty::AssocKind::Const, ty::AssocKind::Fn],
|
||||
trait_did,
|
||||
)
|
||||
.is_some()
|
||||
.filter_by_name_unhygienic(assoc_name.name)
|
||||
.any(|item| self.hygienic_eq(assoc_name, item.ident(self), trait_did))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ pub use self::util::elaborate;
|
||||
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
|
||||
pub use self::util::{get_vtable_index_of_object_method, impl_item_is_final, upcast_choices};
|
||||
pub use self::util::{
|
||||
supertrait_def_ids, supertraits, transitive_bounds, transitive_bounds_that_define_assoc_type,
|
||||
supertrait_def_ids, supertraits, transitive_bounds, transitive_bounds_that_define_assoc_item,
|
||||
SupertraitDefIds,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user