@@ -2088,34 +2088,37 @@ impl<'tcx> TyCtxt<'tcx> {
2088
2088
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
2089
2089
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
2090
2090
pub fn trait_may_define_assoc_type ( self , trait_def_id : DefId , assoc_name : Ident ) -> bool {
2091
- self . super_traits_of ( trait_def_id) . iter ( ) . any ( |trait_did| {
2092
- self . associated_items ( * trait_did)
2093
- . find_by_name_and_kind ( self , assoc_name, ty:: AssocKind :: Type , * trait_did)
2091
+ self . super_traits_of ( trait_def_id) . any ( |trait_did| {
2092
+ self . associated_items ( trait_did)
2093
+ . find_by_name_and_kind ( self , assoc_name, ty:: AssocKind :: Type , trait_did)
2094
2094
. is_some ( )
2095
2095
} )
2096
2096
}
2097
2097
2098
2098
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
2099
2099
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
2100
2100
/// to identify which traits may define a given associated type to help avoid cycle errors.
2101
- /// Returns `Lrc<FxHashSet< DefId>>` so that cloning is cheaper .
2102
- fn super_traits_of ( self , trait_def_id : DefId ) -> Lrc < FxHashSet < DefId > > {
2101
+ /// Returns a ` DefId` iterator .
2102
+ fn super_traits_of ( self , trait_def_id : DefId ) -> impl Iterator < Item = DefId > + ' tcx {
2103
2103
let mut set = FxHashSet :: default ( ) ;
2104
2104
let mut stack = vec ! [ trait_def_id] ;
2105
- while let Some ( trait_did) = stack. pop ( ) {
2106
- if !set. insert ( trait_did) {
2107
- continue ;
2108
- }
2109
2105
2106
+ set. insert ( trait_def_id) ;
2107
+
2108
+ iter:: from_fn ( move || -> Option < DefId > {
2109
+ let trait_did = stack. pop ( ) ?;
2110
2110
let generic_predicates = self . super_predicates_of ( trait_did) ;
2111
+
2111
2112
for ( predicate, _) in generic_predicates. predicates {
2112
2113
if let ty:: PredicateAtom :: Trait ( data, _) = predicate. skip_binders ( ) {
2113
- stack. push ( data. def_id ( ) ) ;
2114
+ if set. insert ( data. def_id ( ) ) {
2115
+ stack. push ( data. def_id ( ) ) ;
2116
+ }
2114
2117
}
2115
2118
}
2116
- }
2117
2119
2118
- Lrc :: new ( set)
2120
+ Some ( trait_did)
2121
+ } )
2119
2122
}
2120
2123
2121
2124
/// Given a closure signature, returns an equivalent fn signature. Detuples
0 commit comments