Skip to content

Commit 3f1ab9d

Browse files
committed
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.
1 parent 51748a8 commit 3f1ab9d

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/librustdoc/clean/types.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl Item {
190190
self.attrs.collapsed_doc_value()
191191
}
192192

193-
crate fn links(&self, cache: &Cache) -> Vec<RenderedLink> {
194-
self.attrs.links(self.def_id.krate, cache)
193+
crate fn links(&self, cache: &Cache, depth: usize) -> Vec<RenderedLink> {
194+
self.attrs.links(self.def_id.krate, cache, depth)
195195
}
196196

197197
crate fn is_crate(&self) -> bool {
@@ -847,9 +847,8 @@ impl Attributes {
847847
/// Gets links as a vector
848848
///
849849
/// Cache must be populated before call
850-
crate fn links(&self, krate: CrateNum, cache: &Cache) -> Vec<RenderedLink> {
850+
crate fn links(&self, krate: CrateNum, cache: &Cache, depth: usize) -> Vec<RenderedLink> {
851851
use crate::html::format::href;
852-
use crate::html::render::CURRENT_DEPTH;
853852

854853
self.links
855854
.iter()
@@ -873,10 +872,7 @@ impl Attributes {
873872
None => {
874873
if let Some(ref fragment) = *fragment {
875874
let url = match cache.extern_locations.get(&krate) {
876-
Some(&(_, _, ExternalLocation::Local)) => {
877-
let depth = CURRENT_DEPTH.with(|l| l.get());
878-
"../".repeat(depth)
879-
}
875+
Some(&(_, _, ExternalLocation::Local)) => "../".repeat(depth),
880876
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
881877
Some(&(_, _, ExternalLocation::Unknown)) | None => String::from(
882878
// NOTE: intentionally doesn't pass crate name to avoid having

src/librustdoc/html/render/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ crate struct Context<'tcx> {
7171
}
7272

7373
impl<'tcx> Context<'tcx> {
74+
pub(super) fn depth(&self) -> usize {
75+
self.current.len()
76+
}
77+
7478
pub(super) fn path(&self, filename: &str) -> PathBuf {
7579
// We use splitn vs Path::extension here because we might get a filename
7680
// like `style.min.css` and we want to process that into

src/librustdoc/html/render/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ fn document_short(
670670
return;
671671
}
672672
if let Some(s) = item.doc_value() {
673-
let mut summary_html = MarkdownSummaryLine(&s, &item.links(&cx.cache)).into_string();
673+
let mut summary_html =
674+
MarkdownSummaryLine(&s, &item.links(&cx.cache, cx.depth())).into_string();
674675

675676
if s.contains('\n') {
676677
let link =
@@ -709,7 +710,7 @@ fn document_full(
709710
) {
710711
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
711712
debug!("Doc block: =====\n{}\n=====", s);
712-
render_markdown(w, cx, &*s, item.links(&cx.cache), prefix, is_hidden);
713+
render_markdown(w, cx, &*s, item.links(&cx.cache, cx.depth()), prefix, is_hidden);
713714
} else if !prefix.is_empty() {
714715
if is_hidden {
715716
w.write_str("<div class=\"docblock hidden\">");
@@ -1487,7 +1488,7 @@ fn render_impl(
14871488
"<div class=\"docblock\">{}</div>",
14881489
Markdown(
14891490
&*dox,
1490-
&i.impl_item.links(&cx.cache),
1491+
&i.impl_item.links(&cx.cache, cx.depth()),
14911492
&mut ids,
14921493
cx.shared.codes,
14931494
cx.shared.edition,

src/librustdoc/html/render/print_item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
297297
</tr>",
298298
name = *myitem.name.as_ref().unwrap(),
299299
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
300-
docs = MarkdownSummaryLine(&doc_value, &myitem.links(&cx.cache)).into_string(),
300+
docs = MarkdownSummaryLine(&doc_value, &myitem.links(&cx.cache, cx.depth()))
301+
.into_string(),
301302
class = myitem.type_(),
302303
add = add,
303304
stab = stab.unwrap_or_else(String::new),

0 commit comments

Comments
 (0)