Rollup merge of #88810 - camelid:cleanup-pt1, r=jyn514
rustdoc: Cleanup `clean` part 1 Split out from #88379. These commits are completely independent of each other, and each is a fairly small change (the last few are new commits; they are not from #88379): - Remove unnecessary `Cache.*_did` fields - rustdoc: Get symbol for `TyParam` directly - Create a valid `Res` in `external_path()` - Remove unused `hir_id` parameter from `resolve_type` - Fix redundant arguments in `external_path()` - Remove unnecessary `is_trait` argument - rustdoc: Cleanup a pattern match in `external_generic_args()` r? ``@jyn514``
This commit is contained in:
commit
b3af37ac7b
6 changed files with 59 additions and 84 deletions
|
@ -51,6 +51,7 @@ use rustc_hir::def::CtorKind;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::Mutability;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use serde::ser::SerializeSeq;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
@ -1067,13 +1068,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>) =
|
||||
|
@ -1163,7 +1164,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, tcx: TyCtxt<'_>) -> bool {
|
||||
let self_type_opt = match *item.kind {
|
||||
clean::MethodItem(ref method, _) => method.decl.self_type(),
|
||||
clean::TyMethodItem(ref method) => method.decl.self_type(),
|
||||
|
@ -1177,7 +1178,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) == tcx.lang_items().owned_box(), false)
|
||||
}
|
||||
SelfTy::SelfValue => (false, false, true),
|
||||
_ => (false, false, false),
|
||||
|
@ -1300,7 +1301,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.tcx())
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1798,13 +1799,13 @@ fn get_methods(
|
|||
for_deref: bool,
|
||||
used_links: &mut FxHashSet<String>,
|
||||
deref_mut: bool,
|
||||
cache: &Cache,
|
||||
tcx: TyCtxt<'_>,
|
||||
) -> 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, tcx) {
|
||||
Some(format!(
|
||||
"<a href=\"#{}\">{}</a>",
|
||||
get_next_url(used_links, format!("method.{}", name)),
|
||||
|
@ -1866,7 +1867,9 @@ 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.tcx())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if !ret.is_empty() {
|
||||
// We want links' order to be reproducible so we don't use unstable sort.
|
||||
|
@ -1884,11 +1887,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);
|
||||
}
|
||||
|
||||
|
@ -1986,10 +1987,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(|| {
|
||||
|
@ -2002,7 +2002,9 @@ 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.tcx())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if !ret.is_empty() {
|
||||
write!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue