@@ -203,9 +203,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
203203 // Traits defined in the current crate can't have impls in upstream
204204 // crates, so we don't bother querying the cstore.
205205 if !trait_id. is_local ( ) {
206- for & cnum in tcx. crates ( ( ) ) . iter ( ) {
207- for & ( impl_def_id, simplified_self_ty) in
208- tcx. implementations_of_trait ( ( cnum, trait_id) ) . iter ( )
206+ for & cnum in tcx. crates ( ( ) ) {
207+ for & ( impl_def_id, simplified_self_ty) in tcx. implementations_of_trait ( ( cnum, trait_id) )
209208 {
210209 if let Some ( simplified_self_ty) = simplified_self_ty {
211210 impls
@@ -239,37 +238,33 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
239238
240239/// Query provider for `incoherent_impls`.
241240pub ( super ) fn incoherent_impls_provider ( tcx : TyCtxt < ' _ > , simp : SimplifiedType ) -> & [ DefId ] {
242- let mut impls = Vec :: new ( ) ;
243- for cnum in iter:: once ( LOCAL_CRATE ) . chain ( tcx. crates ( ( ) ) . iter ( ) . copied ( ) ) {
244- for & impl_def_id in tcx. crate_incoherent_impls ( ( cnum, simp) ) {
245- impls. push ( impl_def_id)
246- }
247- }
248- debug ! ( ?impls) ;
241+ let impls = iter:: once ( & LOCAL_CRATE )
242+ . chain ( tcx. crates ( ( ) ) )
243+ . flat_map ( |& cnum| tcx. crate_incoherent_impls ( ( cnum, simp) ) )
244+ . copied ( ) ;
245+
246+ debug ! ( impls = ?impls. clone( ) . collect:: <Vec <_>>( ) ) ;
249247
250- tcx. arena . alloc_slice ( & impls)
248+ tcx. arena . alloc_from_iter ( impls)
251249}
252250
253251pub ( super ) fn traits_provider ( tcx : TyCtxt < ' _ > , _: LocalCrate ) -> & [ DefId ] {
254- let mut traits = Vec :: new ( ) ;
255- for id in tcx. hir_free_items ( ) {
256- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: Trait | DefKind :: TraitAlias ) {
257- traits. push ( id. owner_id . to_def_id ( ) )
258- }
259- }
252+ let traits = tcx
253+ . hir_free_items ( )
254+ . filter ( |id| matches ! ( tcx. def_kind( id. owner_id) , DefKind :: Trait | DefKind :: TraitAlias ) )
255+ . map ( |id| id. owner_id . to_def_id ( ) ) ;
260256
261- tcx. arena . alloc_slice ( & traits)
257+ tcx. arena . alloc_from_iter ( traits)
262258}
263259
264260pub ( super ) fn trait_impls_in_crate_provider ( tcx : TyCtxt < ' _ > , _: LocalCrate ) -> & [ DefId ] {
265- let mut trait_impls = Vec :: new ( ) ;
266- for id in tcx. hir_free_items ( ) {
267- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: Impl { .. } )
268- && tcx. impl_trait_ref ( id. owner_id ) . is_some ( )
269- {
270- trait_impls. push ( id. owner_id . to_def_id ( ) )
271- }
272- }
273-
274- tcx. arena . alloc_slice ( & trait_impls)
261+ let trait_impls = tcx
262+ . hir_free_items ( )
263+ . filter ( |id| {
264+ matches ! ( tcx. def_kind( id. owner_id) , DefKind :: Impl { .. } )
265+ && tcx. impl_trait_ref ( id. owner_id ) . is_some ( )
266+ } )
267+ . map ( |id| id. owner_id . to_def_id ( ) ) ;
268+
269+ tcx. arena . alloc_from_iter ( trait_impls)
275270}
0 commit comments