diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 25e0be410945..07bd26a4c5eb 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -855,10 +855,12 @@ fn render_impls( traits: &[&&Impl], containing_item: &clean::Item, ) { + let cache = cx.cache(); + let tcx = cx.tcx(); let mut impls = traits .iter() .map(|i| { - let did = i.trait_did_full(cx.cache()).unwrap(); + let did = i.trait_did_full(cache).unwrap(); let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods); let mut buffer = if w.is_for_html() { Buffer::html() } else { Buffer::new() }; render_impl( @@ -868,8 +870,8 @@ fn render_impls( containing_item, assoc_link, RenderMode::Normal, - containing_item.stable_since(cx.tcx()).as_deref(), - containing_item.const_stable_since(cx.tcx()).as_deref(), + containing_item.stable_since(tcx).as_deref(), + containing_item.const_stable_since(tcx).as_deref(), true, None, false, @@ -911,14 +913,16 @@ fn assoc_const( extra: &str, cx: &Context<'_>, ) { + let cache = cx.cache(); + let tcx = cx.tcx(); write!( w, "{}{}const {}: {}", extra, - it.visibility.print_with_space(cx.tcx(), it.def_id, cx.cache()), - naive_assoc_href(it, link, cx.cache()), + it.visibility.print_with_space(tcx, it.def_id, cache), + naive_assoc_href(it, link, cache), it.name.as_ref().unwrap(), - ty.print(cx.cache(), cx.tcx()) + ty.print(cache, tcx) ); } @@ -993,6 +997,8 @@ fn render_assoc_item( parent: ItemType, cx: &Context<'_>, ) { + let cache = cx.cache(); + let tcx = cx.tcx(); let name = meth.name.as_ref().unwrap(); let anchor = format!("#{}.{}", meth.type_(), name); let href = match link { @@ -1007,18 +1013,17 @@ fn render_assoc_item( ItemType::TyMethod }; - href(did, cx.cache()).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor) + href(did, cache).map(|p| format!("{}#{}.{}", p.0, ty, name)).unwrap_or(anchor) } }; - let tcx = cx.tcx(); - let vis = meth.visibility.print_with_space(tcx, meth.def_id, cx.cache()).to_string(); + let vis = meth.visibility.print_with_space(tcx, meth.def_id, cache).to_string(); let constness = header.constness.print_with_space(); let asyncness = header.asyncness.print_with_space(); let unsafety = header.unsafety.print_with_space(); let defaultness = print_default_space(meth.is_default()); let abi = print_abi_with_space(header.abi).to_string(); // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`. - let generics_len = format!("{:#}", g.print(cx.cache(), tcx)).len(); + let generics_len = format!("{:#}", g.print(cache, tcx)).len(); let mut header_len = "fn ".len() + vis.len() + constness.len() @@ -1050,10 +1055,10 @@ fn render_assoc_item( abi, href = href, name = name, - generics = g.print(cx.cache(), cx.tcx()), - decl = d.full_print(cx.cache(), cx.tcx(), header_len, indent, header.asyncness), - spotlight = spotlight_decl(&d, cx.cache(), cx.tcx()), - where_clause = print_where_clause(g, cx.cache(), cx.tcx(), indent, end_newline), + generics = g.print(cache, tcx), + decl = d.full_print(cache, tcx, header_len, indent, header.asyncness), + spotlight = spotlight_decl(&d, cache, tcx), + where_clause = print_where_clause(g, cache, tcx, indent, end_newline), ) } match *item.kind { @@ -1156,6 +1161,8 @@ fn render_assoc_items( Some(v) => v, None => return, }; + let tcx = cx.tcx(); + let cache = cx.cache(); let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none()); if !non_trait.is_empty() { let render_mode = match what { @@ -1170,12 +1177,10 @@ fn render_assoc_items( AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => { let id = cx.derive_id(small_url_encode(format!( "deref-methods-{:#}", - type_.print(cx.cache(), cx.tcx()) + type_.print(cache, tcx) ))); - debug!("Adding {} to deref id map", type_.print(cx.cache(), cx.tcx())); - cx.deref_id_map - .borrow_mut() - .insert(type_.def_id_full(cx.cache()).unwrap(), id.clone()); + debug!("Adding {} to deref id map", type_.print(cache, tcx)); + cx.deref_id_map.borrow_mut().insert(type_.def_id_full(cache).unwrap(), id.clone()); write!( w, "
", id, aliases);
- write!(w, "{}", i.inner_impl().print(cx.cache(), use_absolute, cx.tcx()));
+ write!(w, "{}", i.inner_impl().print(cache, use_absolute, tcx));
if show_def_docs {
for it in &i.inner_impl().items {
if let clean::TypedefItem(ref tydef, _) = *it.kind {
@@ -1450,8 +1454,8 @@ fn render_impl(
Some(&tydef.type_),
AssocItemLink::Anchor(None),
"",
- cx.cache(),
- cx.tcx(),
+ cache,
+ tcx,
);
w.write_str(";");
}
@@ -1464,14 +1468,14 @@ fn render_impl(
"{}",
id,
aliases,
- i.inner_impl().print(cx.cache(), false, cx.tcx())
+ i.inner_impl().print(cache, false, tcx)
);
}
write!(w, "", id);
render_stability_since_raw(
w,
- i.impl_item.stable_since(cx.tcx()).as_deref(),
- i.impl_item.const_stable_since(cx.tcx()).as_deref(),
+ i.impl_item.stable_since(tcx).as_deref(),
+ i.impl_item.const_stable_since(tcx).as_deref(),
outer_version,
outer_const_version,
);
@@ -1517,6 +1521,7 @@ fn render_impl(
) {
let item_type = item.type_();
let name = item.name.as_ref().unwrap();
+ let tcx = cx.tcx();
let render_method_item = match render_mode {
RenderMode::Normal => true,
@@ -1544,8 +1549,8 @@ fn render_impl(
w.write_str("
");
render_stability_since_raw(
w,
- item.stable_since(cx.tcx()).as_deref(),
- item.const_stable_since(cx.tcx()).as_deref(),
+ item.stable_since(tcx).as_deref(),
+ item.const_stable_since(tcx).as_deref(),
outer_version,
outer_const_version,
);
@@ -1564,7 +1569,7 @@ fn render_impl(
link.anchor(&id),
"",
cx.cache(),
- cx.tcx(),
+ tcx,
);
w.write_str("");
}
@@ -1575,8 +1580,8 @@ fn render_impl(
w.write_str("");
render_stability_since_raw(
w,
- item.stable_since(cx.tcx()).as_deref(),
- item.const_stable_since(cx.tcx()).as_deref(),
+ item.stable_since(tcx).as_deref(),
+ item.const_stable_since(tcx).as_deref(),
outer_version,
outer_const_version,
);
@@ -1594,7 +1599,7 @@ fn render_impl(
link.anchor(&id),
"",
cx.cache(),
- cx.tcx(),
+ tcx,
);
w.write_str("");
}
@@ -1898,6 +1903,8 @@ fn small_url_encode(s: String) -> String {
fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
if let Some(v) = cx.cache.impls.get(&it.def_id) {
let mut used_links = FxHashSet::default();
+ let tcx = cx.tcx();
+ let cache = cx.cache();
{
let used_links_bor = &mut used_links;
@@ -1927,7 +1934,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
if let Some(impl_) = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
- .find(|i| i.inner_impl().trait_.def_id_full(cx.cache()) == cx.cache.deref_trait_did)
+ .find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did)
{
sidebar_deref_methods(cx, out, impl_, v);
}
@@ -1938,10 +1945,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
.iter()
.filter_map(|it| {
if let Some(ref i) = it.inner_impl().trait_ {
- let i_display = format!("{:#}", i.print(cx.cache(), cx.tcx()));
+ let i_display = format!("{:#}", i.print(cache, tcx));
let out = Escape(&i_display);
- let encoded =
- small_url_encode(format!("{:#}", i.print(cx.cache(), cx.tcx())));
+ let encoded = small_url_encode(format!("{:#}", i.print(cache, tcx)));
let generated = format!(
"{}{}",
encoded,
@@ -2018,8 +2024,8 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
})
{
debug!("found target, real_target: {:?} {:?}", target, real_target);
- if let Some(did) = target.def_id_full(cx.cache()) {
- if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cx.cache()) {
+ if let Some(did) = target.def_id_full(c) {
+ if let Some(type_did) = impl_.inner_impl().for_.def_id_full(c) {
// `impl Deref