Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/cargo/core/compiler/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ pub fn add_root_urls(
}
Some(RustdocExternMode::Url(s)) => Some(s.to_string()),
};

if matches!(std_url, Some(_))
|| map
.registries
.iter()
.any(|(registry, _)| registry != CRATES_IO_REGISTRY)
{
rustdoc.arg("--extern-html-root-takes-precedence");
}

if let Some(url) = std_url {
for name in &["std", "core", "alloc", "proc_macro"] {
rustdoc.arg("--extern-html-root-url");
Expand Down
4 changes: 1 addition & 3 deletions tests/testsuite/rustdoc_extern_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ fn simple() {
assert!(myfun.contains(r#"href="https://docs.rs/bar/1.0.0/bar/struct.Straw.html""#));
}

#[ignore = "Broken, temporarily disabled until https://github.com/rust-lang/rust/pull/82776 is resolved."]
#[cargo_test]
// #[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
#[cargo_test(nightly, reason = "--extern-html-root-url is unstable")]
Copy link
Copy Markdown
Member

@weihanglo weihanglo Apr 15, 2026

Choose a reason for hiding this comment

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

I feel like this is understood backwards here.

rust-lang/rust#82776 was the reason we disabled the test. See #9824

(I personally don't really have the context of the back-and-forth of these flags though)

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, sorry I didn't dig deeper into git blame. As per my understanding (reading through discussions and histories), --extern-html-root-takes-precedence preserves original behavior that cargo has/had been expecting, so I believe passing this to rustdoc would solve this breakage...?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not really. rust-lang/rust#82776 added --extern-html-root-takes-precedence and

rust-lang/rust#82776 (comment)

The flag here (--extern-html-root-takes-precedence) might be fine, I was just trying to understand what this was being added for. If it was for cargo, then I think this PR wasn't what we really needed. But if it was added for other users, then that would be good to know those use cases.

fn std_docs() {
// Mapping std docs somewhere else.
// For local developers, skip this test if docs aren't installed.
Expand Down