summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-07-30 19:49:01 +0200
committerGitHub <noreply@github.com>2025-07-30 19:49:01 +0200
commitb38ece9021f6682887d729aa0466188eed9b7500 (patch)
tree276d8d1ffb66a5cadb063a0b462543897a860ad7 /tests
parente5e79f8bd428d0b8d26e8240d718b134ef297459 (diff)
parent276c4238a7ee0fa472c951f357642778d60a3bdb (diff)
downloadrust-b38ece9021f6682887d729aa0466188eed9b7500.tar.gz
rust-b38ece9021f6682887d729aa0466188eed9b7500.zip
Rollup merge of #143465 - kornelski:extern-name, r=petrochenkov
Support multiple crate versions in --extern-html-root-url

Rustdoc's `--extern-html-root-url` used to use `tcx.crate_name()` to identify crates, but that used crates' internal names from their metadata, instead of names given to them in `--extern`. That was confusing, because both `--extern…` arguments seem related and use similar syntax. Crucially, this didn't work correctly with Cargo's package aliases or multiple versions of crates.

`sess.opts.externs` lacks `CrateNum`, and `Resolver.extern_prelude` gets destroyed before `rustdoc` has a chance to see it, so I've had to save this mapping in `CStore`.

Just in case, I've kept the previous mapping by crate name as a fallback for crates that weren't matched by their extern name.

Fixes rust-lang/rust#76296
Diffstat (limited to 'tests')
-rw-r--r--tests/rustdoc/extern/extern-html-alias.rs9
-rw-r--r--tests/rustdoc/extern/extern-html-fallback.rs14
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/rustdoc/extern/extern-html-alias.rs b/tests/rustdoc/extern/extern-html-alias.rs
new file mode 100644
index 00000000000..3ff782d3963
--- /dev/null
+++ b/tests/rustdoc/extern/extern-html-alias.rs
@@ -0,0 +1,9 @@
+//@ compile-flags:-Z unstable-options --extern-html-root-url externs_name=https://renamed.example.com  --extern-html-root-url empty=https://bad.invalid
+//@ aux-crate:externs_name=empty.rs
+//@ edition: 2018
+
+extern crate externs_name as renamed;
+
+//@ has extern_html_alias/index.html
+//@ has - '//a/@href' 'https://renamed.example.com/empty/index.html'
+pub use renamed as yet_different_name;
diff --git a/tests/rustdoc/extern/extern-html-fallback.rs b/tests/rustdoc/extern/extern-html-fallback.rs
new file mode 100644
index 00000000000..ddac9bf713c
--- /dev/null
+++ b/tests/rustdoc/extern/extern-html-fallback.rs
@@ -0,0 +1,14 @@
+//@ compile-flags:-Z unstable-options --extern-html-root-url yet_another_name=https://bad.invalid --extern-html-root-url renamed_privately=https://bad.invalid --extern-html-root-url renamed_locally=https://bad.invalid --extern-html-root-url empty=https://localhost
+//@ aux-crate:externs_name=empty.rs
+//@ edition: 2018
+
+mod m {
+    pub extern crate externs_name as renamed_privately;
+}
+
+// renaming within the crate's source code is not supposed to affect CLI flags
+extern crate externs_name as renamed_locally;
+
+//@ has extern_html_fallback/index.html
+//@ has - '//a/@href' 'https://localhost/empty/index.html'
+pub use crate::renamed_locally as yet_another_name;