Skip to content

Commit a19078a

Browse files
committed
Update associated_item_def_ids
1 parent c213717 commit a19078a

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ rustc_queries! {
259259

260260
Other {
261261
/// Maps from an impl/trait def-id to a list of the def-ids of its items
262-
query associated_item_def_ids(_: DefId) -> Lrc<Vec<DefId>> {}
262+
query associated_item_def_ids(_: DefId) -> &'tcx [DefId] {}
263263

264264
/// Maps from a trait item to the trait item "descriptor"
265265
query associated_item(_: DefId) -> ty::AssociatedItem {}

src/librustc/ty/mod.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
30833083

30843084
pub struct AssociatedItemsIterator<'a, 'gcx: 'tcx, 'tcx: 'a> {
30853085
tcx: TyCtxt<'a, 'gcx, 'tcx>,
3086-
def_ids: Lrc<Vec<DefId>>,
3086+
def_ids: &'gcx [DefId],
30873087
next_index: usize,
30883088
}
30893089

@@ -3172,26 +3172,27 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31723172

31733173
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31743174
def_id: DefId)
3175-
-> Lrc<Vec<DefId>> {
3175+
-> &'tcx [DefId] {
31763176
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
31773177
let item = tcx.hir().expect_item_by_hir_id(id);
3178-
let vec: Vec<_> = match item.node {
3178+
match item.node {
31793179
hir::ItemKind::Trait(.., ref trait_item_refs) => {
3180-
trait_item_refs.iter()
3181-
.map(|trait_item_ref| trait_item_ref.id)
3182-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3183-
.collect()
3180+
tcx.arena.alloc_from_iter(
3181+
trait_item_refs.iter()
3182+
.map(|trait_item_ref| trait_item_ref.id)
3183+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3184+
)
31843185
}
31853186
hir::ItemKind::Impl(.., ref impl_item_refs) => {
3186-
impl_item_refs.iter()
3187-
.map(|impl_item_ref| impl_item_ref.id)
3188-
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3189-
.collect()
3187+
tcx.arena.alloc_from_iter(
3188+
impl_item_refs.iter()
3189+
.map(|impl_item_ref| impl_item_ref.id)
3190+
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
3191+
)
31903192
}
3191-
hir::ItemKind::TraitAlias(..) => vec![],
3193+
hir::ItemKind::TraitAlias(..) => &[],
31923194
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
3193-
};
3194-
Lrc::new(vec)
3195+
}
31953196
}
31963197

31973198
fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {

src/librustc_metadata/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ crate-type = ["dylib"]
1313
flate2 = "1.0"
1414
log = "0.4"
1515
memmap = "0.6"
16+
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
1617
rustc = { path = "../librustc" }
1718
rustc_data_structures = { path = "../librustc_data_structures" }
1819
errors = { path = "../librustc_errors", package = "rustc_errors" }

src/librustc_metadata/cstore_impl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::hir::map::definitions::DefPathTable;
2020
use rustc::util::nodemap::DefIdMap;
2121
use rustc_data_structures::svh::Svh;
2222

23+
use smallvec::SmallVec;
2324
use std::any::Any;
2425
use rustc_data_structures::sync::Lrc;
2526
use std::sync::Arc;
@@ -107,10 +108,10 @@ provide! { <'tcx> tcx, def_id, other, cdata,
107108
}
108109
variances_of => { tcx.arena.alloc_from_iter(cdata.get_item_variances(def_id.index)) }
109110
associated_item_def_ids => {
110-
let mut result = vec![];
111+
let mut result = SmallVec::<[_; 8]>::new();
111112
cdata.each_child_of_item(def_id.index,
112113
|child| result.push(child.def.def_id()), tcx.sess);
113-
Lrc::new(result)
114+
tcx.arena.alloc_from_iter(result)
114115
}
115116
associated_item => { cdata.get_associated_item(def_id.index) }
116117
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }

0 commit comments

Comments
 (0)