Don't share id_map
and deref_id_map
All the tests passed, so it doesn't seem they need to be shared. Plus they should be item/page-specific. I'm not sure why they were shared before. I think the reason `id_map` worked as a shared value before is that it is cleared before rendering each item (in `render_item`). And then I'm guessing `deref_id_map` worked because it's a hashmap keyed by `DefId`, so there was no overlap (though I'm guessing we could have had issues in the future). Note that `id_map` currently still has to be cleared because otherwise child items would inherit the `id_map` of their parent. I'm hoping to figure out a way to stop cloning `Context`, but until then we have to reset `id_map`.
This commit is contained in:
parent
3bc879e76b
commit
4c51a66d67
2 changed files with 20 additions and 21 deletions
|
@ -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<String>);
|
||||
|
@ -121,11 +121,6 @@ crate struct SharedContext<'tcx> {
|
|||
crate edition: Edition,
|
||||
codes: ErrorCodes,
|
||||
playground: Option<markdown::Playground>,
|
||||
/// The map used to ensure all generated 'id=' attributes are unique.
|
||||
id_map: RefCell<IdMap>,
|
||||
/// Tracks section IDs for `Deref` targets so they match in both the main
|
||||
/// body and the sidebar.
|
||||
deref_id_map: RefCell<FxHashMap<DefId, String>>,
|
||||
all: RefCell<AllTypes>,
|
||||
/// 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,
|
||||
"<div class=\"docblock{}\">{}{}</div>",
|
||||
|
@ -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!(
|
||||
"<details><summary>{}</summary>{}</details>",
|
||||
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,
|
||||
"<div class=\"docblock\">{}</div>",
|
||||
|
@ -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::<Vec<_>>();
|
||||
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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue