Make provided_trait_methods use impl Iterator

This commit is contained in:
Jonas Schievink 2020-02-07 21:33:23 +01:00
parent 52f77110d4
commit e0cb1ae24a
5 changed files with 9 additions and 17 deletions

View File

@ -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 {

View File

@ -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()),
);
}
}
}

View File

@ -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();

View File

@ -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());

View File

@ -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();