diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 50d160ccd82..c2dfb64b2ab 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -6,7 +6,7 @@ use std::rc::Rc;
use std::sync::mpsc::channel;
use rustc_data_structures::fx::FxHashMap;
-use rustc_hir::def_id::LOCAL_CRATE;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
@@ -30,7 +30,7 @@ use crate::formats::item_type::ItemType;
use crate::formats::FormatRenderer;
use crate::html::escape::Escape;
use crate::html::format::Buffer;
-use crate::html::markdown::{self, plain_text_summary, ErrorCodes};
+use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
use crate::html::{layout, sources};
/// Major driving force in all rustdoc rendering. This contains information
@@ -52,6 +52,11 @@ crate struct Context<'tcx> {
/// real location of an item. This is used to allow external links to
/// publicly reused items to redirect to the right location.
pub(super) render_redirect_pages: bool,
+ /// The map used to ensure all generated 'id=' attributes are unique.
+ pub(super) id_map: RefCell,
+ /// Tracks section IDs for `Deref` targets so they match in both the main
+ /// body and the sidebar.
+ pub(super) deref_id_map: RefCell>,
/// Shared mutable state.
///
/// Issue for improving the situation: [#82381][]
@@ -72,7 +77,7 @@ crate struct Context<'tcx> {
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
#[cfg(target_arch = "x86_64")]
-rustc_data_structures::static_assert_size!(Context<'_>, 72);
+rustc_data_structures::static_assert_size!(Context<'_>, 152);
impl<'tcx> Context<'tcx> {
pub(super) fn path(&self, filename: &str) -> PathBuf {
@@ -95,7 +100,7 @@ impl<'tcx> Context<'tcx> {
}
pub(super) fn derive_id(&self, id: String) -> String {
- let mut map = self.shared.id_map.borrow_mut();
+ let mut map = self.id_map.borrow_mut();
map.derive(id)
}
@@ -153,8 +158,8 @@ impl<'tcx> Context<'tcx> {
};
{
- self.shared.id_map.borrow_mut().reset();
- self.shared.id_map.borrow_mut().populate(&INITIAL_IDS);
+ self.id_map.borrow_mut().reset();
+ self.id_map.borrow_mut().populate(&INITIAL_IDS);
}
if !self.render_redirect_pages {
@@ -387,8 +392,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
edition,
codes: ErrorCodes::from(unstable_features.is_nightly_build()),
playground,
- id_map: RefCell::new(id_map),
- deref_id_map: RefCell::new(FxHashMap::default()),
all: RefCell::new(AllTypes::new()),
errors: receiver,
redirections: if generate_redirect_map { Some(Default::default()) } else { None },
@@ -418,6 +421,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
current: Vec::new(),
dst,
render_redirect_pages: false,
+ id_map: RefCell::new(id_map),
+ deref_id_map: RefCell::new(FxHashMap::default()),
shared: Rc::new(scx),
cache: Rc::new(cache),
};
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index c074b789e74..339c3ec15f6 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -70,7 +70,7 @@ use crate::html::format::{
PrintWithSpace, WhereClause,
};
use crate::html::layout;
-use crate::html::markdown::{self, ErrorCodes, IdMap, Markdown, MarkdownHtml, MarkdownSummaryLine};
+use crate::html::markdown::{self, ErrorCodes, Markdown, MarkdownHtml, MarkdownSummaryLine};
/// A pair of name and its optional document.
crate type NameDoc = (String, Option);
@@ -121,11 +121,6 @@ crate struct SharedContext<'tcx> {
crate edition: Edition,
codes: ErrorCodes,
playground: Option,
- /// The map used to ensure all generated 'id=' attributes are unique.
- id_map: RefCell,
- /// Tracks section IDs for `Deref` targets so they match in both the main
- /// body and the sidebar.
- deref_id_map: RefCell>,
all: RefCell,
/// Storage for the errors produced while generating documentation so they
/// can be printed together at the end.
@@ -650,7 +645,7 @@ fn render_markdown(
prefix: &str,
is_hidden: bool,
) {
- let mut ids = cx.shared.id_map.borrow_mut();
+ let mut ids = cx.id_map.borrow_mut();
write!(
w,
"{}{}
",
@@ -810,7 +805,7 @@ fn short_item_info(
if let Some(note) = note {
let note = note.as_str();
- let mut ids = cx.shared.id_map.borrow_mut();
+ let mut ids = cx.id_map.borrow_mut();
let html = MarkdownHtml(
¬e,
&mut ids,
@@ -849,7 +844,7 @@ fn short_item_info(
message.push_str(&format!(" ({})", feature));
if let Some(unstable_reason) = reason {
- let mut ids = cx.shared.id_map.borrow_mut();
+ let mut ids = cx.id_map.borrow_mut();
message = format!(
"{}
{} ",
message,
@@ -1189,8 +1184,7 @@ fn render_assoc_items(
type_.print(cx.cache())
)));
debug!("Adding {} to deref id map", type_.print(cx.cache()));
- cx.shared
- .deref_id_map
+ cx.deref_id_map
.borrow_mut()
.insert(type_.def_id_full(cx.cache()).unwrap(), id.clone());
write!(
@@ -1497,7 +1491,7 @@ fn render_impl(
}
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
- let mut ids = cx.shared.id_map.borrow_mut();
+ let mut ids = cx.id_map.borrow_mut();
write!(
w,
"{}
",
@@ -2046,7 +2040,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
.flat_map(|i| get_methods(i.inner_impl(), true, &mut used_links, deref_mut, c))
.collect::>();
if !ret.is_empty() {
- let deref_id_map = cx.shared.deref_id_map.borrow();
+ let deref_id_map = cx.deref_id_map.borrow();
let id = deref_id_map
.get(&real_target.def_id_full(cx.cache()).unwrap())
.expect("Deref section without derived id");