Improve calculation of "Impls on Foreign Types"
This commit is contained in:
parent
29e972dc60
commit
37d363879e
@ -7,6 +7,7 @@ use rustc_hir::def_id::DefId;
|
||||
crate use renderer::{run_format, FormatRenderer};
|
||||
|
||||
use crate::clean::{self, ItemId};
|
||||
use cache::Cache;
|
||||
|
||||
/// Specifies whether rendering directly implemented trait items or ones from a certain Deref
|
||||
/// impl.
|
||||
@ -60,4 +61,28 @@ impl Impl {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if this is an implementation on a "local" type, meaning:
|
||||
// the type is in the current crate, or the type and the trait are both
|
||||
// re-exported by the current crate.
|
||||
pub(crate) fn is_on_local_type(&self, cache: &Cache) -> bool {
|
||||
let for_type = &self.inner_impl().for_;
|
||||
if let Some(for_type_did) = for_type.def_id(cache) {
|
||||
// The "for" type is local if it's in the paths for the current crate.
|
||||
if cache.paths.contains_key(&for_type_did) {
|
||||
return true;
|
||||
}
|
||||
if let Some(trait_did) = self.trait_did() {
|
||||
// The "for" type and the trait are from the same crate. That could
|
||||
// be different from the current crate, for instance when both were
|
||||
// re-exported from some other crate. But they are local with respect to
|
||||
// each other.
|
||||
if for_type_did.krate == trait_did.krate {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -2287,9 +2287,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
|
||||
if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
|
||||
let mut res = implementors
|
||||
.iter()
|
||||
.filter(|i| {
|
||||
i.inner_impl().for_.def_id(cache).map_or(false, |d| !cache.paths.contains_key(&d))
|
||||
})
|
||||
.filter(|i| !i.is_on_local_type(cache))
|
||||
.filter_map(|i| extract_for_impl_name(&i.impl_item, cx))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -818,9 +818,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||
}
|
||||
}
|
||||
|
||||
let (local, foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
|
||||
i.inner_impl().for_.def_id(cache).map_or(true, |d| cache.paths.contains_key(&d))
|
||||
});
|
||||
let (local, foreign) =
|
||||
implementors.iter().partition::<Vec<_>, _>(|i| i.is_on_local_type(cache));
|
||||
|
||||
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
||||
local.iter().partition(|i| i.inner_impl().kind.is_auto());
|
||||
|
@ -13,5 +13,5 @@ extern crate real_gimli;
|
||||
// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//h3[@class="code-header in-band"]' 'impl Deref for EndianSlice'
|
||||
pub use realcore::Deref;
|
||||
|
||||
// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//h3[@class="code-header in-band"]' 'impl Join for Foo'
|
||||
// @has foo/trait.Join.html '//*[@id="impl-Join"]//h3[@class="code-header in-band"]' 'impl Join for Foo'
|
||||
pub use realcore::Join;
|
||||
|
Loading…
x
Reference in New Issue
Block a user