Skip to content

rustdoc: Cleanup clean part 1 #88810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 19 additions & 22 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) =
Expand Down Expand Up @@ -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(),
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}
};

Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}

Expand Down Expand Up @@ -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(|| {
Expand All @@ -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!(
Expand Down