Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Don't use CURRENT_DEPTH in clean/types.rs #82745

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl Item {
self.attrs.collapsed_doc_value()
}

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

crate fn is_crate(&self) -> bool {
Expand Down Expand Up @@ -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<RenderedLink> {
crate fn links(&self, krate: &CrateNum, cache: &Cache, depth: usize) -> Vec<RenderedLink> {
use crate::html::format::href;
use crate::html::render::CURRENT_DEPTH;

self.links
.iter()
Expand All @@ -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(),
Expand Down
12 changes: 8 additions & 4 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ crate struct SharedContext<'tcx> {
}

impl<'tcx> Context<'tcx> {
fn depth(&self) -> usize {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add docs here if you like. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that seems useful.

self.current.len()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused - did current already exist? How is it kept in sync with CURRENT_DEPTH?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CURRENT_DEPTH is set to self.current.len() in render_item(). self.current should always be the same when rendering a particular item since it represents the namespace hierarchy.

Copy link
Member Author

@camelid camelid Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can combine this PR with #82815 if you like so that we don't have to worry about keeping CURRENT_DEPTH in sync with depth().

}

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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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("<div class=\"docblock hidden\">");
Expand Down Expand Up @@ -2241,7 +2245,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
</tr>",
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),
Expand Down Expand Up @@ -3862,7 +3866,7 @@ fn render_impl(
"<div class=\"docblock\">{}</div>",
Markdown(
&*dox,
&i.impl_item.links(&cx.cache),
&i.impl_item.links(&cx.cache, cx.depth()),
&mut ids,
cx.shared.codes,
cx.shared.edition,
Expand Down