super_traits_of is now a query
This commit is contained in:
parent
6631215e54
commit
b60a214c51
@ -433,7 +433,13 @@ rustc_queries! {
|
||||
/// full predicates are available (note that supertraits have
|
||||
/// additional acyclicity requirements).
|
||||
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
|
||||
|
@ -6,7 +6,6 @@ mod errors;
|
||||
mod generics;
|
||||
|
||||
use crate::bounds::Bounds;
|
||||
use crate::collect::super_traits_of;
|
||||
use crate::collect::PlaceholderHirTyCollector;
|
||||
use crate::errors::{
|
||||
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`
|
||||
/// 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 {
|
||||
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()
|
||||
.associated_items(trait_did)
|
||||
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, trait_did)
|
||||
.associated_items(*trait_did)
|
||||
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, *trait_did)
|
||||
.is_some()
|
||||
})
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ pub fn provide(providers: &mut Providers) {
|
||||
projection_ty_from_predicates,
|
||||
explicit_predicates_of,
|
||||
super_predicates_of,
|
||||
super_traits_of,
|
||||
super_predicates_that_define_assoc_type,
|
||||
trait_explicit_predicates_and_bounds,
|
||||
type_param_predicates,
|
||||
@ -653,14 +654,14 @@ impl 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() {
|
||||
super_traits_of(self.tcx, trait_did).any(|trait_did| {
|
||||
self.tcx.super_traits_of(trait_did).iter().any(|trait_did| {
|
||||
self.tcx
|
||||
.associated_items(trait_did)
|
||||
.associated_items(*trait_did)
|
||||
.find_by_name_and_kind(
|
||||
self.tcx,
|
||||
assoc_name,
|
||||
ty::AssocKind::Type,
|
||||
trait_did,
|
||||
*trait_did,
|
||||
)
|
||||
.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 stack = vec![trait_def_id];
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user