-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Fix relative path handling for --extern-html-root-url #152977
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,8 +386,9 @@ impl<'tcx> Context<'tcx> { | |
| let e = ExternalCrate { crate_num: cnum }; | ||
| (e.name(self.tcx()), e.src_root(self.tcx())) | ||
| } | ||
| ExternalLocation::Remote(ref s) => { | ||
| root = s.to_string(); | ||
| ExternalLocation::Remote { ref url, .. } => { | ||
| // FIXME: relative extern URLs are not depth-adjusted for source pages | ||
| root = url.to_string(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can't properly handle relative extern locations here for now, could we add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added FIXME comments on both sites. |
||
| let e = ExternalCrate { crate_num: cnum }; | ||
| (e.name(self.tcx()), e.src_root(self.tcx())) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,7 +280,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { | |
| types::ExternalCrate { | ||
| name: e.name(self.tcx).to_string(), | ||
| html_root_url: match external_location { | ||
| ExternalLocation::Remote(s) => Some(s.clone()), | ||
| // FIXME: relative extern URLs are not resolved here | ||
| ExternalLocation::Remote { url, .. } => Some(url.clone()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, perhaps add a |
||
| _ => None, | ||
| }, | ||
| path: self | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While looking for more bugs, I wrote a few test cases that you probably want to incorporate. All of them passed, so it seems fine. Just bringing them up: diff --git a/tests/rustdoc-html/extern/extern-html-root-url-relative.rs b/tests/rustdoc-html/extern/extern-html-root-url-relative.rs
index df6ebf1aedd..ba2b50c6bf2 100644
--- a/tests/rustdoc-html/extern/extern-html-root-url-relative.rs
+++ b/tests/rustdoc-html/extern/extern-html-root-url-relative.rs
@@ -1,4 +1,4 @@
-//@ compile-flags:-Z unstable-options --extern-html-root-url core=../ --extern-html-root-takes-precedence
+//@ compile-flags:-Z unstable-options --extern-html-root-url core=../ --extern-html-root-takes-precedence --generate-link-to-definition
// At depth 1 (top-level), the href should be ../core/...
//@ has extern_html_root_url_relative/index.html
@@ -9,7 +9,19 @@
// At depth 2 (inside a module), the href should be ../../core/...
pub mod nested {
//@ has extern_html_root_url_relative/nested/index.html
- //@ has - '//a/@href' '../../core/iter/index.html'
+ //@ has - '//a/@href' '../../core/future/index.html'
#[doc(no_inline)]
- pub use std::iter;
+ pub use std::future;
}
+
+// Also depth 2, but for an intra-doc link.
+//@ has extern_html_root_url_relative/intra_doc_link/index.html
+//@ has - '//a/@href' '../../core/ptr/fn.write.html'
+/// [write](<core::ptr::write()>)
+pub mod intra_doc_link {
+}
+
+// link-to-definition
+//@ has src/extern_html_root_url_relative/extern-html-root-url-relative.rs.html
+//@ has - '//a/@href' '../../core/iter/index.html'
+//@ has - '//a/@href' '../../core/future/index.html'
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, thanks for the extra coverage. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //@ compile-flags:-Z unstable-options --extern-html-root-url core=../ --extern-html-root-takes-precedence --generate-link-to-definition | ||
|
|
||
| // At depth 1 (top-level), the href should be ../core/... | ||
| //@ has extern_html_root_url_relative/index.html | ||
| //@ has - '//a/@href' '../core/iter/index.html' | ||
| #[doc(no_inline)] | ||
| pub use std::iter; | ||
|
|
||
| // At depth 2 (inside a module), the href should be ../../core/... | ||
| pub mod nested { | ||
| //@ has extern_html_root_url_relative/nested/index.html | ||
| //@ has - '//a/@href' '../../core/future/index.html' | ||
| #[doc(no_inline)] | ||
| pub use std::future; | ||
| } | ||
|
|
||
| // Also depth 2, but for an intra-doc link. | ||
| //@ has extern_html_root_url_relative/intra_doc_link/index.html | ||
| //@ has - '//a/@href' '../../core/ptr/fn.write.html' | ||
| /// [write](<core::ptr::write()>) | ||
| pub mod intra_doc_link { | ||
| } | ||
|
|
||
| // link-to-definition | ||
| //@ has src/extern_html_root_url_relative/extern-html-root-url-relative.rs.html | ||
| //@ has - '//a/@href' '../../core/iter/index.html' | ||
| //@ has - '//a/@href' '../../core/future/index.html' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes me wonder whether we should do further sanity checking here, eg ensuring that
urldoes not have query or fragment parts - but that can be dealt with as a separate issue/PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, worth a follow-up.