Update implementations_of_trait and all_trait_implementations
This commit is contained in:
parent
95dfd82666
commit
093940ddc4
@ -724,12 +724,12 @@ rustc_queries! {
|
||||
|
||||
TypeChecking {
|
||||
query implementations_of_trait(_: (CrateNum, DefId))
|
||||
-> Lrc<Vec<DefId>> {
|
||||
-> &'tcx [DefId] {
|
||||
no_force
|
||||
desc { "looking up implementations of a trait in a crate" }
|
||||
}
|
||||
query all_trait_implementations(_: CrateNum)
|
||||
-> Lrc<Vec<DefId>> {
|
||||
-> &'tcx [DefId] {
|
||||
desc { "looking up all (?) trait implementations" }
|
||||
}
|
||||
}
|
||||
|
@ -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) }
|
||||
|
@ -1024,31 +1024,34 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
.map(|index| self.local_def_id(index)))
|
||||
}
|
||||
|
||||
pub fn get_implementations_for_trait(&self,
|
||||
filter: Option<DefId>,
|
||||
result: &mut Vec<DefId>) {
|
||||
pub fn get_implementations_for_trait(
|
||||
&self,
|
||||
tcx: TyCtxt<'_, 'tcx, '_>,
|
||||
filter: Option<DefId>,
|
||||
) -> &'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))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user