super_traits_of is now a query

This commit is contained in:
Santiago Pastorino 2020-11-21 18:13:04 -03:00
parent 6631215e54
commit b60a214c51
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 16 additions and 10 deletions

View File

@ -433,7 +433,13 @@ rustc_queries! {
/// full predicates are available (note that supertraits have /// full predicates are available (note that supertraits have
/// additional acyclicity requirements). /// additional acyclicity requirements).
query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) } desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
}
/// Maps from the `DefId` of a trait to the list of
/// all the ancestors super traits.
query super_traits_of(key: DefId) -> FxHashSet<DefId> {
desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) }
} }
/// Maps from the `DefId` of a trait to the list of /// Maps from the `DefId` of a trait to the list of

View File

@ -6,7 +6,6 @@ mod errors;
mod generics; mod generics;
use crate::bounds::Bounds; use crate::bounds::Bounds;
use crate::collect::super_traits_of;
use crate::collect::PlaceholderHirTyCollector; use crate::collect::PlaceholderHirTyCollector;
use crate::errors::{ use crate::errors::{
AmbiguousLifetimeBound, MultipleRelaxedDefaultBounds, TraitObjectDeclaredWithNoTraits, AmbiguousLifetimeBound, MultipleRelaxedDefaultBounds, TraitObjectDeclaredWithNoTraits,
@ -923,10 +922,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name` /// 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`. /// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
fn trait_may_define_assoc_type(&self, trait_def_id: DefId, assoc_name: Ident) -> bool { fn trait_may_define_assoc_type(&self, trait_def_id: DefId, assoc_name: Ident) -> bool {
super_traits_of(self.tcx(), trait_def_id).any(|trait_did| { self.tcx().super_traits_of(trait_def_id).iter().any(|trait_did| {
self.tcx() self.tcx()
.associated_items(trait_did) .associated_items(*trait_did)
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, trait_did) .find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, *trait_did)
.is_some() .is_some()
}) })
} }

View File

@ -80,6 +80,7 @@ pub fn provide(providers: &mut Providers) {
projection_ty_from_predicates, projection_ty_from_predicates,
explicit_predicates_of, explicit_predicates_of,
super_predicates_of, super_predicates_of,
super_traits_of,
super_predicates_that_define_assoc_type, super_predicates_that_define_assoc_type,
trait_explicit_predicates_and_bounds, trait_explicit_predicates_and_bounds,
type_param_predicates, type_param_predicates,
@ -653,14 +654,14 @@ impl ItemCtxt<'tcx> {
hir::GenericBound::Trait(poly_trait_ref, _) => { hir::GenericBound::Trait(poly_trait_ref, _) => {
let trait_ref = &poly_trait_ref.trait_ref; let trait_ref = &poly_trait_ref.trait_ref;
if let Some(trait_did) = trait_ref.trait_def_id() { if let Some(trait_did) = trait_ref.trait_def_id() {
super_traits_of(self.tcx, trait_did).any(|trait_did| { self.tcx.super_traits_of(trait_did).iter().any(|trait_did| {
self.tcx self.tcx
.associated_items(trait_did) .associated_items(*trait_did)
.find_by_name_and_kind( .find_by_name_and_kind(
self.tcx, self.tcx,
assoc_name, assoc_name,
ty::AssocKind::Type, ty::AssocKind::Type,
trait_did, *trait_did,
) )
.is_some() .is_some()
}) })
@ -1125,7 +1126,7 @@ fn super_predicates_that_define_assoc_type(
} }
} }
pub fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> impl Iterator<Item = DefId> { fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
let mut set = FxHashSet::default(); let mut set = FxHashSet::default();
let mut stack = vec![trait_def_id]; let mut stack = vec![trait_def_id];
while let Some(trait_did) = stack.pop() { while let Some(trait_did) = stack.pop() {
@ -1185,7 +1186,7 @@ pub fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> impl Iterator<It
} }
} }
set.into_iter() set
} }
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {