Make super_traits_of return an iterator
This commit is contained in:
parent
35bf466a27
commit
504d27cb0c
1 changed files with 15 additions and 12 deletions
|
@ -2088,9 +2088,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// 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`.
|
||||||
pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Ident) -> bool {
|
pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Ident) -> bool {
|
||||||
self.super_traits_of(trait_def_id).iter().any(|trait_did| {
|
self.super_traits_of(trait_def_id).any(|trait_did| {
|
||||||
self.associated_items(*trait_did)
|
self.associated_items(trait_did)
|
||||||
.find_by_name_and_kind(self, assoc_name, ty::AssocKind::Type, *trait_did)
|
.find_by_name_and_kind(self, assoc_name, ty::AssocKind::Type, trait_did)
|
||||||
.is_some()
|
.is_some()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2098,24 +2098,27 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
|
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
|
||||||
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
|
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
|
||||||
/// to identify which traits may define a given associated type to help avoid cycle errors.
|
/// to identify which traits may define a given associated type to help avoid cycle errors.
|
||||||
/// Returns `Lrc<FxHashSet<DefId>>` so that cloning is cheaper.
|
/// Returns a `DefId` iterator.
|
||||||
fn super_traits_of(self, trait_def_id: DefId) -> Lrc<FxHashSet<DefId>> {
|
fn super_traits_of(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
|
||||||
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() {
|
|
||||||
if !set.insert(trait_did) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
set.insert(trait_def_id);
|
||||||
|
|
||||||
|
iter::from_fn(move || -> Option<DefId> {
|
||||||
|
let trait_did = stack.pop()?;
|
||||||
let generic_predicates = self.super_predicates_of(trait_did);
|
let generic_predicates = self.super_predicates_of(trait_did);
|
||||||
|
|
||||||
for (predicate, _) in generic_predicates.predicates {
|
for (predicate, _) in generic_predicates.predicates {
|
||||||
if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() {
|
if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() {
|
||||||
stack.push(data.def_id());
|
if set.insert(data.def_id()) {
|
||||||
|
stack.push(data.def_id());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Lrc::new(set)
|
Some(trait_did)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a closure signature, returns an equivalent fn signature. Detuples
|
/// Given a closure signature, returns an equivalent fn signature. Detuples
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue