') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Fix relative extern URL depth on source pages by arferreira · Pull Request #153160 · rust-lang/rust · GitHub
Skip to content

Fix relative extern URL depth on source pages - #153160

Open
arferreira wants to merge 2 commits into
rust-lang:mainfrom
arferreira:fix-relative-extern-url-root-path
Open

Fix relative extern URL depth on source pages#153160
arferreira wants to merge 2 commits into
rust-lang:mainfrom
arferreira:fix-relative-extern-url-root-path

Conversation

@arferreira

@arferreiraarferreira commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

View all comments

Source pages with --extern-html-root-url pointing to a relative URL like ../ were generating links with one extra ../. So instead of ../../core/iter/index.html you'd get ../../../core/iter/index.html. Took a while to notice because htmldocck.py uses substring matching — ../../core/ is a substring of ../../../core/ so the test passed anyway.

Two root causes. remote_url_prefix was using cx.current.len() for depth, but during source rendering cx.current is empty — SourceCollector doesn't do module descent. Source pages live under src/<crate_name>/ so the real depth is 2, not 0. On top of that, make_href was trying to compensate by prepending root_path to relative remote URLs (there was a FIXME about this), which just made it worse — ../../ + ../core/iter/ = ../../../core/iter/.

Fix: added remote_item_depth(root_path, doc_depth) that counts ../ segments in root_path when present, falls back to doc_depth otherwise. With the right depth in remote_url_prefix, make_href no longer needs to touch remote URLs at all — so url_parts now returns is_remote = true for all Remote locations. Also renamed is_absoluteis_remote since the semantics were always about "don't modify this URL", not about whether it has a scheme.

Added !has assertions to the test so the wrong URL gets caught explicitly next time.

Follow-up to #152977.

r? @notriddle

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Feb 27, 2026
@rust-log-analyzer

This comment has been minimized.

Comment threadsrc/librustdoc/html/format.rs Outdated
@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 27, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@arferreira
arferreiraforce-pushed the fix-relative-extern-url-root-path branch from d71f355 to bfeb902CompareFebruary 27, 2026 12:01
@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 27, 2026
@rust-log-analyzer

This comment has been minimized.

@arferreira

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rust-log-analyzer

This comment has been minimized.

@arferreira
arferreiraforce-pushed the fix-relative-extern-url-root-path branch from 0f28723 to 6017689CompareFebruary 27, 2026 14:54
@notriddle

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-borsBot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6017689 has been approved by notriddle

It is now in the queue for this repository.

@rust-borsrust-borsBot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 27, 2026
@rust-bors

This comment has been minimized.

@arferreira
arferreiraforce-pushed the fix-relative-extern-url-root-path branch from 6017689 to 59b37bbCompareMarch 12, 2026 00:31
@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@notriddle

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-borsBot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 59b37bb has been approved by notriddle

It is now in the queue for this repository.

@rust-borsrust-borsBot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 12, 2026
@rust-bors

This comment has been minimized.

rust-borsBot pushed a commit that referenced this pull request Mar 12, 2026
… r=notriddle
Fix relative extern URL depth on source pages
Source pages with `--extern-html-root-url` pointing to a relative URL like `../` were generating links with one extra `../`. So instead of `../../core/iter/index.html` you'd get `../../../core/iter/index.html`. Took a while to notice because `htmldocck.py` uses substring matching — `../../core/` is a substring of `../../../core/` so the test passed anyway.
Two root causes. `remote_url_prefix` was using `cx.current.len()` for depth, but during source rendering `cx.current` is empty — `SourceCollector` doesn't do module descent. Source pages live under `src/<crate_name>/` so the real depth is 2, not 0. On top of that, `make_href` was trying to compensate by prepending `root_path` to relative remote URLs (there was a FIXME about this), which just made it worse — `../../` + `../core/iter/` = `../../../core/iter/`.
Fix: added `remote_item_depth(root_path, doc_depth)` that counts `../` segments in `root_path` when present, falls back to `doc_depth` otherwise. With the right depth in `remote_url_prefix`, `make_href` no longer needs to touch remote URLs at all — so `url_parts` now returns `is_remote = true` for all `Remote` locations. Also renamed `is_absolute` → `is_remote` since the semantics were always about "don't modify this URL", not about whether it has a scheme.
Added `!has` assertions to the test so the wrong URL gets caught explicitly next time.
Follow-up to #152977.
r? @notriddle
@rust-borsrust-borsBot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 12, 2026
@rust-bors

rust-borsBot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

💔 Test for e95d0cd failed: CI. Failed job:

@TKanXTKanX mentioned this pull request Mar 12, 2026
@rust-log-analyzer

This comment has been minimized.

@Zalathar

Copy link
Copy Markdown
Member

@bors retry

@rust-borsrust-borsBot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 12, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 12, 2026
…-root-path, r=notriddle
Fix relative extern URL depth on source pages
Source pages with `--extern-html-root-url` pointing to a relative URL like `../` were generating links with one extra `../`. So instead of `../../core/iter/index.html` you'd get `../../../core/iter/index.html`. Took a while to notice because `htmldocck.py` uses substring matching — `../../core/` is a substring of `../../../core/` so the test passed anyway.
Two root causes. `remote_url_prefix` was using `cx.current.len()` for depth, but during source rendering `cx.current` is empty — `SourceCollector` doesn't do module descent. Source pages live under `src/<crate_name>/` so the real depth is 2, not 0. On top of that, `make_href` was trying to compensate by prepending `root_path` to relative remote URLs (there was a FIXME about this), which just made it worse — `../../` + `../core/iter/` = `../../../core/iter/`.
Fix: added `remote_item_depth(root_path, doc_depth)` that counts `../` segments in `root_path` when present, falls back to `doc_depth` otherwise. With the right depth in `remote_url_prefix`, `make_href` no longer needs to touch remote URLs at all — so `url_parts` now returns `is_remote = true` for all `Remote` locations. Also renamed `is_absolute` → `is_remote` since the semantics were always about "don't modify this URL", not about whether it has a scheme.
Added `!has` assertions to the test so the wrong URL gets caught explicitly next time.
Follow-up to rust-lang#152977.
r? @notriddle
@ZalatharZalathar mentioned this pull request Mar 12, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 12, 2026
…-root-path, r=notriddle
Fix relative extern URL depth on source pages
Source pages with `--extern-html-root-url` pointing to a relative URL like `../` were generating links with one extra `../`. So instead of `../../core/iter/index.html` you'd get `../../../core/iter/index.html`. Took a while to notice because `htmldocck.py` uses substring matching — `../../core/` is a substring of `../../../core/` so the test passed anyway.
Two root causes. `remote_url_prefix` was using `cx.current.len()` for depth, but during source rendering `cx.current` is empty — `SourceCollector` doesn't do module descent. Source pages live under `src/<crate_name>/` so the real depth is 2, not 0. On top of that, `make_href` was trying to compensate by prepending `root_path` to relative remote URLs (there was a FIXME about this), which just made it worse — `../../` + `../core/iter/` = `../../../core/iter/`.
Fix: added `remote_item_depth(root_path, doc_depth)` that counts `../` segments in `root_path` when present, falls back to `doc_depth` otherwise. With the right depth in `remote_url_prefix`, `make_href` no longer needs to touch remote URLs at all — so `url_parts` now returns `is_remote = true` for all `Remote` locations. Also renamed `is_absolute` → `is_remote` since the semantics were always about "don't modify this URL", not about whether it has a scheme.
Added `!has` assertions to the test so the wrong URL gets caught explicitly next time.
Follow-up to rust-lang#152977.
r? @notriddle
@ZalatharZalathar mentioned this pull request Mar 12, 2026
rust-borsBot pushed a commit that referenced this pull request Mar 12, 2026
Rollup of 7 pull requests
Successful merges:
- #153736 (add test that an incomplete feature emits a warning)
- #153160 (Fix relative extern URL depth on source pages)
- #153432 (Fix some comments about dataflow analysis.)
- #153694 (fix(query): Pass Query Key to `value_from_cycle_error`)
- #153717 (unused_macro_rules switched used and unused comments)
- #153748 (editorconfig: css uses tabs)
- #153750 (rustc-dev-guide subtree update)
@rust-bors

rust-borsBot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 59b37bb with merge c66e4b8...

Workflow: https://github.com/rust-lang/rust/actions/runs/22995536645

rust-borsBot pushed a commit that referenced this pull request Mar 12, 2026
… r=notriddle
Fix relative extern URL depth on source pages
Source pages with `--extern-html-root-url` pointing to a relative URL like `../` were generating links with one extra `../`. So instead of `../../core/iter/index.html` you'd get `../../../core/iter/index.html`. Took a while to notice because `htmldocck.py` uses substring matching — `../../core/` is a substring of `../../../core/` so the test passed anyway.
Two root causes. `remote_url_prefix` was using `cx.current.len()` for depth, but during source rendering `cx.current` is empty — `SourceCollector` doesn't do module descent. Source pages live under `src/<crate_name>/` so the real depth is 2, not 0. On top of that, `make_href` was trying to compensate by prepending `root_path` to relative remote URLs (there was a FIXME about this), which just made it worse — `../../` + `../core/iter/` = `../../../core/iter/`.
Fix: added `remote_item_depth(root_path, doc_depth)` that counts `../` segments in `root_path` when present, falls back to `doc_depth` otherwise. With the right depth in `remote_url_prefix`, `make_href` no longer needs to touch remote URLs at all — so `url_parts` now returns `is_remote = true` for all `Remote` locations. Also renamed `is_absolute` → `is_remote` since the semantics were always about "don't modify this URL", not about whether it has a scheme.
Added `!has` assertions to the test so the wrong URL gets caught explicitly next time.
Follow-up to #152977.
r? @notriddle
@Zalathar

Copy link
Copy Markdown
Member

Failed in rollup: #153761 (comment)

@bors r-

@rust-borsrust-borsBot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 12, 2026
@rust-bors

rust-borsBot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#153761), which was unapproved.

Auto build was cancelled due to unapproval. Cancelled workflows:

@Zalathar

Copy link
Copy Markdown
Member

@bors try jobs=dist-x86_64-linux-alt

@rust-bors

This comment has been minimized.

rust-borsBot pushed a commit that referenced this pull request Mar 12, 2026
… r=<try>
Fix relative extern URL depth on source pages
try-job: dist-x86_64-linux-alt
@rust-bors

rust-borsBot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 052b44b (052b44bdc2f95e775fc97e3f8679c579d666f71a, parent: d1ee5e59a964a419b84b760812a35075034f4861)

@rust-bors

rust-borsBot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #161990) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@arferreira@rust-log-analyzer@rustbot@notriddle@Zalathar