Remove unnecessary Cache.*_did
fields
They can be obtained by accessing the `TyCtxt` where they are needed.
This commit is contained in:
parent
497ee321af
commit
44e6f2e90f
3 changed files with 19 additions and 29 deletions
|
@ -29,10 +29,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
|
|||
let krate = cx.tcx.hir().krate();
|
||||
let module = crate::visit_ast::RustdocVisitor::new(cx).visit(krate);
|
||||
|
||||
cx.cache.deref_trait_did = cx.tcx.lang_items().deref_trait();
|
||||
cx.cache.deref_mut_trait_did = cx.tcx.lang_items().deref_mut_trait();
|
||||
cx.cache.owned_box_did = cx.tcx.lang_items().owned_box();
|
||||
|
||||
let mut externs = Vec::new();
|
||||
for &cnum in cx.tcx.crates(()).iter() {
|
||||
externs.push(ExternalCrate { crate_num: cnum });
|
||||
|
|
|
@ -98,9 +98,6 @@ crate struct Cache {
|
|||
stripped_mod: bool,
|
||||
|
||||
crate search_index: Vec<IndexItem>,
|
||||
crate deref_trait_did: Option<DefId>,
|
||||
crate deref_mut_trait_did: Option<DefId>,
|
||||
crate owned_box_did: Option<DefId>,
|
||||
|
||||
// In rare case where a structure is defined in one module but implemented
|
||||
// in another, if the implementing module is parsed before defining module,
|
||||
|
|
|
@ -1069,13 +1069,13 @@ fn render_assoc_items(
|
|||
return;
|
||||
}
|
||||
if !traits.is_empty() {
|
||||
let deref_impl = traits
|
||||
.iter()
|
||||
.find(|t| t.inner_impl().trait_.def_id_full(cache) == cache.deref_trait_did);
|
||||
let deref_impl = traits.iter().find(|t| {
|
||||
t.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_trait()
|
||||
});
|
||||
if let Some(impl_) = deref_impl {
|
||||
let has_deref_mut = traits
|
||||
.iter()
|
||||
.any(|t| t.inner_impl().trait_.def_id_full(cache) == cache.deref_mut_trait_did);
|
||||
let has_deref_mut = traits.iter().any(|t| {
|
||||
t.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_mut_trait()
|
||||
});
|
||||
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut);
|
||||
}
|
||||
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) =
|
||||
|
@ -1165,7 +1165,7 @@ fn render_deref_methods(
|
|||
}
|
||||
}
|
||||
|
||||
fn should_render_item(item: &clean::Item, deref_mut_: bool, cache: &Cache) -> bool {
|
||||
fn should_render_item(item: &clean::Item, deref_mut_: bool, cx: &Context<'_>) -> bool {
|
||||
let self_type_opt = match *item.kind {
|
||||
clean::MethodItem(ref method, _) => method.decl.self_type(),
|
||||
clean::TyMethodItem(ref method) => method.decl.self_type(),
|
||||
|
@ -1179,7 +1179,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, cache: &Cache) -> bo
|
|||
(mutability == Mutability::Mut, false, false)
|
||||
}
|
||||
SelfTy::SelfExplicit(clean::ResolvedPath { did, .. }) => {
|
||||
(false, Some(did) == cache.owned_box_did, false)
|
||||
(false, Some(did) == cx.tcx().lang_items().owned_box(), false)
|
||||
}
|
||||
SelfTy::SelfValue => (false, false, true),
|
||||
_ => (false, false, false),
|
||||
|
@ -1302,7 +1302,7 @@ fn render_impl(
|
|||
&& match render_mode {
|
||||
RenderMode::Normal => true,
|
||||
RenderMode::ForDeref { mut_: deref_mut_ } => {
|
||||
should_render_item(&item, deref_mut_, cx.cache())
|
||||
should_render_item(&item, deref_mut_, cx)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1800,13 +1800,13 @@ fn get_methods(
|
|||
for_deref: bool,
|
||||
used_links: &mut FxHashSet<String>,
|
||||
deref_mut: bool,
|
||||
cache: &Cache,
|
||||
cx: &Context<'_>,
|
||||
) -> Vec<String> {
|
||||
i.items
|
||||
.iter()
|
||||
.filter_map(|item| match item.name {
|
||||
Some(ref name) if !name.is_empty() && item.is_method() => {
|
||||
if !for_deref || should_render_item(item, deref_mut, cache) {
|
||||
if !for_deref || should_render_item(item, deref_mut, cx) {
|
||||
Some(format!(
|
||||
"<a href=\"#{}\">{}</a>",
|
||||
get_next_url(used_links, format!("method.{}", name)),
|
||||
|
@ -1868,7 +1868,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
|||
let mut ret = v
|
||||
.iter()
|
||||
.filter(|i| i.inner_impl().trait_.is_none())
|
||||
.flat_map(move |i| get_methods(i.inner_impl(), false, used_links_bor, false, cache))
|
||||
.flat_map(move |i| get_methods(i.inner_impl(), false, used_links_bor, false, cx))
|
||||
.collect::<Vec<_>>();
|
||||
if !ret.is_empty() {
|
||||
// We want links' order to be reproducible so we don't use unstable sort.
|
||||
|
@ -1886,11 +1886,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
|
|||
}
|
||||
|
||||
if v.iter().any(|i| i.inner_impl().trait_.is_some()) {
|
||||
if let Some(impl_) = v
|
||||
.iter()
|
||||
.filter(|i| i.inner_impl().trait_.is_some())
|
||||
.find(|i| i.inner_impl().trait_.def_id_full(cache) == cache.deref_trait_did)
|
||||
{
|
||||
if let Some(impl_) = v.iter().filter(|i| i.inner_impl().trait_.is_some()).find(|i| {
|
||||
i.inner_impl().trait_.def_id_full(cache) == cx.tcx().lang_items().deref_trait()
|
||||
}) {
|
||||
sidebar_deref_methods(cx, out, impl_, v);
|
||||
}
|
||||
|
||||
|
@ -1988,10 +1986,9 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
|
|||
}
|
||||
}
|
||||
}
|
||||
let deref_mut = v
|
||||
.iter()
|
||||
.filter(|i| i.inner_impl().trait_.is_some())
|
||||
.any(|i| i.inner_impl().trait_.def_id_full(c) == c.deref_mut_trait_did);
|
||||
let deref_mut = v.iter().filter(|i| i.inner_impl().trait_.is_some()).any(|i| {
|
||||
i.inner_impl().trait_.def_id_full(c) == cx.tcx().lang_items().deref_mut_trait()
|
||||
});
|
||||
let inner_impl = target
|
||||
.def_id_full(c)
|
||||
.or_else(|| {
|
||||
|
@ -2004,7 +2001,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
|
|||
let mut ret = impls
|
||||
.iter()
|
||||
.filter(|i| i.inner_impl().trait_.is_none())
|
||||
.flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut, c))
|
||||
.flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut, cx))
|
||||
.collect::<Vec<_>>();
|
||||
if !ret.is_empty() {
|
||||
write!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue