diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 2e2cb2db838..d6dbd49d173 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -724,12 +724,12 @@ rustc_queries! { TypeChecking { query implementations_of_trait(_: (CrateNum, DefId)) - -> Lrc> { + -> &'tcx [DefId] { no_force desc { "looking up implementations of a trait in a crate" } } query all_trait_implementations(_: CrateNum) - -> Lrc> { + -> &'tcx [DefId] { desc { "looking up all (?) trait implementations" } } } diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index d94c07ce072..6b06a0712e1 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -208,18 +208,12 @@ provide! { <'tcx> tcx, def_id, other, cdata, extra_filename => { cdata.root.extra_filename.clone() } - implementations_of_trait => { - let mut result = vec![]; - let filter = Some(other); - cdata.get_implementations_for_trait(filter, &mut result); - Lrc::new(result) + cdata.get_implementations_for_trait(tcx, Some(other)) } all_trait_implementations => { - let mut result = vec![]; - cdata.get_implementations_for_trait(None, &mut result); - Lrc::new(result) + cdata.get_implementations_for_trait(tcx, None) } visibility => { cdata.get_visibility(def_id.index) } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index a2ea0fd6f55..c4037dcfac0 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -1024,31 +1024,34 @@ impl<'a, 'tcx> CrateMetadata { .map(|index| self.local_def_id(index))) } - pub fn get_implementations_for_trait(&self, - filter: Option, - result: &mut Vec) { + pub fn get_implementations_for_trait( + &self, + tcx: TyCtxt<'_, 'tcx, '_>, + filter: Option, + ) -> &'tcx [DefId] { if self.proc_macros.is_some() { // proc-macro crates export no trait impls. - return + return &[] } // Do a reverse lookup beforehand to avoid touching the crate_num // hash map in the loop below. let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) { Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)), - Some(None) => return, + Some(None) => return &[], None => None, }; if let Some(filter) = filter { - if let Some(impls) = self.trait_impls - .get(&filter) { - result.extend(impls.decode(self).map(|idx| self.local_def_id(idx))); + if let Some(impls) = self.trait_impls.get(&filter) { + tcx.arena.alloc_from_iter(impls.decode(self).map(|idx| self.local_def_id(idx))) + } else { + &[] } } else { - for impls in self.trait_impls.values() { - result.extend(impls.decode(self).map(|idx| self.local_def_id(idx))); - } + tcx.arena.alloc_from_iter(self.trait_impls.values().flat_map(|impls| { + impls.decode(self).map(|idx| self.local_def_id(idx)) + })) } }