Skip to content

Commit

Permalink
Make provided_trait_methods use impl Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Feb 8, 2020
1 parent 52f7711 commit e0cb1ae
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/librustc/ty/mod.rs
Expand Up @@ -2705,11 +2705,10 @@ impl<'tcx> TyCtxt<'tcx> {
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
}

pub fn provided_trait_methods(self, id: DefId) -> Vec<&'tcx AssocItem> {
pub fn provided_trait_methods(self, id: DefId) -> impl Iterator<Item = &'tcx AssocItem> {
self.associated_items(id)
.iter()
.filter(|item| item.kind == AssocKind::Method && item.defaultness.has_value())
.collect()
}

pub fn trait_relevant_for_never(self, did: DefId) -> bool {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_passes/reachable.rs
Expand Up @@ -362,12 +362,12 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
return;
}

let provided_trait_methods = self.tcx.provided_trait_methods(trait_def_id);
self.worklist.reserve(provided_trait_methods.len());
for default_method in provided_trait_methods {
let hir_id = self.tcx.hir().as_local_hir_id(default_method.def_id).unwrap();
self.worklist.push(hir_id);
}
// FIXME(#53488) remove `let`
let tcx = self.tcx;
self.worklist.extend(
tcx.provided_trait_methods(trait_def_id)
.map(|assoc| tcx.hir().as_local_hir_id(assoc.def_id).unwrap()),
);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/blanket_impl.rs
Expand Up @@ -87,7 +87,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.cx
.tcx
.provided_trait_methods(trait_def_id)
.into_iter()
.map(|meth| meth.ident.to_string())
.collect();

Expand Down
4 changes: 1 addition & 3 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -402,9 +402,7 @@ pub fn build_impl(

let provided = trait_
.def_id()
.map(|did| {
tcx.provided_trait_methods(did).into_iter().map(|meth| meth.ident.to_string()).collect()
})
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.to_string()).collect())
.unwrap_or_default();

debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -2108,11 +2108,7 @@ impl Clean<Vec<Item>> for doctree::Impl<'_> {
let provided: FxHashSet<String> = trait_
.def_id()
.map(|did| {
cx.tcx
.provided_trait_methods(did)
.into_iter()
.map(|meth| meth.ident.to_string())
.collect()
cx.tcx.provided_trait_methods(did).map(|meth| meth.ident.to_string()).collect()
})
.unwrap_or_default();

Expand Down

0 comments on commit e0cb1ae

Please sign in to comment.