Construct `AssociatedItems` from an iterator instead of a `Vec`

This commit is contained in:
Dylan MacKenzie 2020-02-19 12:55:59 -08:00
parent 186cbfad89
commit a0212ba40f
2 changed files with 2 additions and 3 deletions

View File

@ -277,7 +277,7 @@ pub struct AssociatedItems {
impl AssociatedItems {
/// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order.
pub fn new(items_in_def_order: Vec<ty::AssocItem>) -> Self {
pub fn new(items_in_def_order: impl IntoIterator<Item = ty::AssocItem>) -> Self {
let items = items_in_def_order.into_iter().map(|item| (item.ident.name, item)).collect();
AssociatedItems { items }
}

View File

@ -211,8 +211,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
}
fn associated_items<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::AssociatedItems {
let items =
tcx.associated_item_def_ids(def_id).iter().map(|did| tcx.associated_item(*did)).collect();
let items = tcx.associated_item_def_ids(def_id).iter().map(|did| tcx.associated_item(*did));
tcx.arena.alloc(ty::AssociatedItems::new(items))
}