@@ -2177,84 +2177,80 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
21772177 /// Walk the generics of the item for a trait bound whose self type
21782178 /// corresponds to the expected res, and return the trait def id.
21792179 fn for_each_trait_bound_on_res ( & self , expected_res : Res ) -> impl Iterator < Item = DefId > {
2180- std:: iter:: from_coroutine (
2181- #[ coroutine]
2182- move || {
2183- let mut scope = self . scope ;
2184- loop {
2185- let hir_id = match * scope {
2186- Scope :: Binder { hir_id, .. } => Some ( hir_id) ,
2187- Scope :: Root { opt_parent_item : Some ( parent_def_id) } => {
2188- Some ( self . tcx . local_def_id_to_hir_id ( parent_def_id) )
2189- }
2190- Scope :: Body { .. }
2191- | Scope :: ObjectLifetimeDefault { .. }
2192- | Scope :: Supertrait { .. }
2193- | Scope :: TraitRefBoundary { .. }
2194- | Scope :: LateBoundary { .. }
2195- | Scope :: Opaque { .. }
2196- | Scope :: Root { opt_parent_item : None } => None ,
2197- } ;
2180+ gen move {
2181+ let mut scope = self . scope ;
2182+ loop {
2183+ let hir_id = match * scope {
2184+ Scope :: Binder { hir_id, .. } => Some ( hir_id) ,
2185+ Scope :: Root { opt_parent_item : Some ( parent_def_id) } => {
2186+ Some ( self . tcx . local_def_id_to_hir_id ( parent_def_id) )
2187+ }
2188+ Scope :: Body { .. }
2189+ | Scope :: ObjectLifetimeDefault { .. }
2190+ | Scope :: Supertrait { .. }
2191+ | Scope :: TraitRefBoundary { .. }
2192+ | Scope :: LateBoundary { .. }
2193+ | Scope :: Opaque { .. }
2194+ | Scope :: Root { opt_parent_item : None } => None ,
2195+ } ;
21982196
2199- if let Some ( hir_id) = hir_id {
2200- let node = self . tcx . hir_node ( hir_id) ;
2201- // If this is a `Self` bound in a trait, yield the trait itself.
2202- // Specifically, we don't need to look at any supertraits since
2203- // we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2204- if let Res :: SelfTyParam { trait_ : _ } = expected_res
2205- && let hir:: Node :: Item ( item) = node
2206- && let hir:: ItemKind :: Trait ( ..) = item. kind
2207- {
2208- // Yield the trait's def id. Supertraits will be
2209- // elaborated from that.
2210- yield item. owner_id . def_id . to_def_id ( ) ;
2211- } else if let Some ( generics) = node. generics ( ) {
2212- for pred in generics. predicates {
2213- let hir:: WherePredicateKind :: BoundPredicate ( pred) = pred. kind
2214- else {
2215- continue ;
2216- } ;
2217- let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , bounded_path) ) =
2218- pred. bounded_ty . kind
2219- else {
2220- continue ;
2221- } ;
2222- // Match the expected res.
2223- if bounded_path. res != expected_res {
2224- continue ;
2225- }
2226- for pred in pred. bounds {
2227- match pred {
2228- hir:: GenericBound :: Trait ( poly_trait_ref) => {
2229- if let Some ( def_id) =
2230- poly_trait_ref. trait_ref . trait_def_id ( )
2231- {
2232- yield def_id;
2233- }
2197+ if let Some ( hir_id) = hir_id {
2198+ let node = self . tcx . hir_node ( hir_id) ;
2199+ // If this is a `Self` bound in a trait, yield the trait itself.
2200+ // Specifically, we don't need to look at any supertraits since
2201+ // we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2202+ if let Res :: SelfTyParam { trait_ : _ } = expected_res
2203+ && let hir:: Node :: Item ( item) = node
2204+ && let hir:: ItemKind :: Trait ( ..) = item. kind
2205+ {
2206+ // Yield the trait's def id. Supertraits will be
2207+ // elaborated from that.
2208+ yield item. owner_id . def_id . to_def_id ( ) ;
2209+ } else if let Some ( generics) = node. generics ( ) {
2210+ for pred in generics. predicates {
2211+ let hir:: WherePredicateKind :: BoundPredicate ( pred) = pred. kind else {
2212+ continue ;
2213+ } ;
2214+ let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , bounded_path) ) =
2215+ pred. bounded_ty . kind
2216+ else {
2217+ continue ;
2218+ } ;
2219+ // Match the expected res.
2220+ if bounded_path. res != expected_res {
2221+ continue ;
2222+ }
2223+ for pred in pred. bounds {
2224+ match pred {
2225+ hir:: GenericBound :: Trait ( poly_trait_ref) => {
2226+ if let Some ( def_id) =
2227+ poly_trait_ref. trait_ref . trait_def_id ( )
2228+ {
2229+ yield def_id;
22342230 }
2235- hir:: GenericBound :: Outlives ( _)
2236- | hir:: GenericBound :: Use ( _, _) => { }
22372231 }
2232+ hir:: GenericBound :: Outlives ( _)
2233+ | hir:: GenericBound :: Use ( _, _) => { }
22382234 }
22392235 }
22402236 }
22412237 }
2238+ }
22422239
2243- match * scope {
2244- Scope :: Binder { s, .. }
2245- | Scope :: Body { s, .. }
2246- | Scope :: ObjectLifetimeDefault { s, .. }
2247- | Scope :: Supertrait { s, .. }
2248- | Scope :: TraitRefBoundary { s }
2249- | Scope :: LateBoundary { s, .. }
2250- | Scope :: Opaque { s, .. } => {
2251- scope = s;
2252- }
2253- Scope :: Root { .. } => break ,
2240+ match * scope {
2241+ Scope :: Binder { s, .. }
2242+ | Scope :: Body { s, .. }
2243+ | Scope :: ObjectLifetimeDefault { s, .. }
2244+ | Scope :: Supertrait { s, .. }
2245+ | Scope :: TraitRefBoundary { s }
2246+ | Scope :: LateBoundary { s, .. }
2247+ | Scope :: Opaque { s, .. } => {
2248+ scope = s;
22542249 }
2250+ Scope :: Root { .. } => break ,
22552251 }
2256- } ,
2257- )
2252+ }
2253+ }
22582254 }
22592255}
22602256
0 commit comments