From fa3ad97bb5e0605dbdfb0580fdfaa8dae3b822e8 Mon Sep 17 00:00:00 2001 From: Camelid Date: Wed, 3 Mar 2021 20:20:34 -0800 Subject: [PATCH] rustdoc: Don't use `CURRENT_DEPTH` in `clean/types.rs` This part actually wasn't that hard. Ending the use of it in `html/format.rs` is probably going to be *a lot* harder. --- src/librustdoc/clean/types.rs | 8 +++----- src/librustdoc/html/render/mod.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 09ba0e2740f1b..e175a9261715e 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -190,8 +190,8 @@ impl Item { self.attrs.collapsed_doc_value() } - crate fn links(&self, cache: &Cache) -> Vec { - self.attrs.links(&self.def_id.krate, cache) + crate fn links(&self, cache: &Cache, depth: usize) -> Vec { + self.attrs.links(&self.def_id.krate, cache, depth) } crate fn is_crate(&self) -> bool { @@ -844,9 +844,8 @@ impl Attributes { /// Gets links as a vector /// /// Cache must be populated before call - crate fn links(&self, krate: &CrateNum, cache: &Cache) -> Vec { + crate fn links(&self, krate: &CrateNum, cache: &Cache, depth: usize) -> Vec { use crate::html::format::href; - use crate::html::render::CURRENT_DEPTH; self.links .iter() @@ -871,7 +870,6 @@ impl Attributes { if let Some(ref fragment) = *fragment { let url = match cache.extern_locations.get(krate) { Some(&(_, _, ExternalLocation::Local)) => { - let depth = CURRENT_DEPTH.with(|l| l.get()); "../".repeat(depth) } Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(), diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 394c57c7214e7..ce53f56589f6f 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -170,6 +170,10 @@ crate struct SharedContext<'tcx> { } impl<'tcx> Context<'tcx> { + fn depth(&self) -> usize { + self.current.len() + } + fn path(&self, filename: &str) -> PathBuf { // We use splitn vs Path::extension here because we might get a filename // like `style.min.css` and we want to process that into @@ -1912,7 +1916,7 @@ fn document_short( return; } if let Some(s) = item.doc_value() { - let mut summary_html = MarkdownSummaryLine(&s, &item.links(&cx.cache)).into_string(); + let mut summary_html = MarkdownSummaryLine(&s, &item.links(&cx.cache, cx.depth())).into_string(); if s.contains('\n') { let link = @@ -1951,7 +1955,7 @@ fn document_full( ) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); - render_markdown(w, cx, &*s, item.links(&cx.cache), prefix, is_hidden); + render_markdown(w, cx, &*s, item.links(&cx.cache, cx.depth()), prefix, is_hidden); } else if !prefix.is_empty() { if is_hidden { w.write_str("
"); @@ -2241,7 +2245,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl ", name = *myitem.name.as_ref().unwrap(), stab_tags = extra_info_tags(myitem, item, cx.tcx()), - docs = MarkdownSummaryLine(&doc_value, &myitem.links(&cx.cache)).into_string(), + docs = MarkdownSummaryLine(&doc_value, &myitem.links(&cx.cache, cx.depth())).into_string(), class = myitem.type_(), add = add, stab = stab.unwrap_or_else(String::new), @@ -3862,7 +3866,7 @@ fn render_impl( "
{}
", Markdown( &*dox, - &i.impl_item.links(&cx.cache), + &i.impl_item.links(&cx.cache, cx.depth()), &mut ids, cx.shared.codes, cx.shared.edition,