Skip to content

Commit b60a214

Browse files
committed
super_traits_of is now a query
1 parent 6631215 commit b60a214

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,13 @@ rustc_queries! {
433433
/// full predicates are available (note that supertraits have
434434
/// additional acyclicity requirements).
435435
query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
436-
desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
436+
desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
437+
}
438+
439+
/// Maps from the `DefId` of a trait to the list of
440+
/// all the ancestors super traits.
441+
query super_traits_of(key: DefId) -> FxHashSet<DefId> {
442+
desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) }
437443
}
438444

439445
/// Maps from the `DefId` of a trait to the list of

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod errors;
66
mod generics;
77

88
use crate::bounds::Bounds;
9-
use crate::collect::super_traits_of;
109
use crate::collect::PlaceholderHirTyCollector;
1110
use crate::errors::{
1211
AmbiguousLifetimeBound, MultipleRelaxedDefaultBounds, TraitObjectDeclaredWithNoTraits,
@@ -923,10 +922,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
923922
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
924923
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
925924
fn trait_may_define_assoc_type(&self, trait_def_id: DefId, assoc_name: Ident) -> bool {
926-
super_traits_of(self.tcx(), trait_def_id).any(|trait_did| {
925+
self.tcx().super_traits_of(trait_def_id).iter().any(|trait_did| {
927926
self.tcx()
928-
.associated_items(trait_did)
929-
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, trait_did)
927+
.associated_items(*trait_did)
928+
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, *trait_did)
930929
.is_some()
931930
})
932931
}

compiler/rustc_typeck/src/collect.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn provide(providers: &mut Providers) {
8080
projection_ty_from_predicates,
8181
explicit_predicates_of,
8282
super_predicates_of,
83+
super_traits_of,
8384
super_predicates_that_define_assoc_type,
8485
trait_explicit_predicates_and_bounds,
8586
type_param_predicates,
@@ -653,14 +654,14 @@ impl ItemCtxt<'tcx> {
653654
hir::GenericBound::Trait(poly_trait_ref, _) => {
654655
let trait_ref = &poly_trait_ref.trait_ref;
655656
if let Some(trait_did) = trait_ref.trait_def_id() {
656-
super_traits_of(self.tcx, trait_did).any(|trait_did| {
657+
self.tcx.super_traits_of(trait_did).iter().any(|trait_did| {
657658
self.tcx
658-
.associated_items(trait_did)
659+
.associated_items(*trait_did)
659660
.find_by_name_and_kind(
660661
self.tcx,
661662
assoc_name,
662663
ty::AssocKind::Type,
663-
trait_did,
664+
*trait_did,
664665
)
665666
.is_some()
666667
})
@@ -1125,7 +1126,7 @@ fn super_predicates_that_define_assoc_type(
11251126
}
11261127
}
11271128

1128-
pub fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> impl Iterator<Item = DefId> {
1129+
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
11291130
let mut set = FxHashSet::default();
11301131
let mut stack = vec![trait_def_id];
11311132
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
11851186
}
11861187
}
11871188

1188-
set.into_iter()
1189+
set
11891190
}
11901191

11911192
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {

0 commit comments

Comments
 (0)