Skip to content

Commit 6486544

Browse files
committed
Update implementations_of_trait and all_trait_implementations
1 parent cc60f16 commit 6486544

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/librustc/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,12 @@ rustc_queries! {
726726

727727
TypeChecking {
728728
query implementations_of_trait(_: (CrateNum, DefId))
729-
-> Lrc<Vec<DefId>> {
729+
-> &'tcx [DefId] {
730730
no_force
731731
desc { "looking up implementations of a trait in a crate" }
732732
}
733733
query all_trait_implementations(_: CrateNum)
734-
-> Lrc<Vec<DefId>> {
734+
-> &'tcx [DefId] {
735735
desc { "looking up all (?) trait implementations" }
736736
}
737737
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,12 @@ provide! { <'tcx> tcx, def_id, other, cdata,
208208

209209
extra_filename => { cdata.root.extra_filename.clone() }
210210

211-
212211
implementations_of_trait => {
213-
let mut result = vec![];
214-
let filter = Some(other);
215-
cdata.get_implementations_for_trait(filter, &mut result);
216-
Lrc::new(result)
212+
cdata.get_implementations_for_trait(tcx, Some(other))
217213
}
218214

219215
all_trait_implementations => {
220-
let mut result = vec![];
221-
cdata.get_implementations_for_trait(None, &mut result);
222-
Lrc::new(result)
216+
cdata.get_implementations_for_trait(tcx, None)
223217
}
224218

225219
visibility => { cdata.get_visibility(def_id.index) }

src/librustc_metadata/decoder.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,31 +1023,34 @@ impl<'a, 'tcx> CrateMetadata {
10231023
.map(|index| self.local_def_id(index)))
10241024
}
10251025

1026-
pub fn get_implementations_for_trait(&self,
1027-
filter: Option<DefId>,
1028-
result: &mut Vec<DefId>) {
1026+
pub fn get_implementations_for_trait(
1027+
&self,
1028+
tcx: TyCtxt<'_, 'tcx, '_>,
1029+
filter: Option<DefId>,
1030+
) -> &'tcx [DefId] {
10291031
if self.proc_macros.is_some() {
10301032
// proc-macro crates export no trait impls.
1031-
return
1033+
return &[]
10321034
}
10331035

10341036
// Do a reverse lookup beforehand to avoid touching the crate_num
10351037
// hash map in the loop below.
10361038
let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
10371039
Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
1038-
Some(None) => return,
1040+
Some(None) => return &[],
10391041
None => None,
10401042
};
10411043

10421044
if let Some(filter) = filter {
1043-
if let Some(impls) = self.trait_impls
1044-
.get(&filter) {
1045-
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
1045+
if let Some(impls) = self.trait_impls.get(&filter) {
1046+
tcx.arena.alloc_from_iter(impls.decode(self).map(|idx| self.local_def_id(idx)))
1047+
} else {
1048+
&[]
10461049
}
10471050
} else {
1048-
for impls in self.trait_impls.values() {
1049-
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
1050-
}
1051+
tcx.arena.alloc_from_iter(self.trait_impls.values().flat_map(|impls| {
1052+
impls.decode(self).map(|idx| self.local_def_id(idx))
1053+
}))
10511054
}
10521055
}
10531056

0 commit comments

Comments
 (0)