Skip to content

Commit 4d276d7

Browse files
committed
Auto merge of #155307 - Urgau:rustdoc-stabilize-remap-path-prefix, r=GuillaumeGomez
Stabilize `--remap-path-prefix` in rustdoc # Stabilization report of `--remap-path-prefix` in rustdoc ## Summary `rustc` supports remapping source paths prefixes as a best effort in all compiler generated output, including compiler diagnostics, debugging information, macro expansions, documentation, doctests, etc. This is useful for normalizing build products, for example, by removing the current directory out of the paths emitted into object files. This stabilization stabilize the same flag used by `rustc` in `rustdoc`. There are no tracking issue. Stabilization was discussed at the last meeting, [#t-rustdoc/meetings > 2026-04-13 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2026-04-13/near/585264347). ### What is stabilized The rustdoc `--remap-path-prefix` flag is being stabilized by this PR. (It's equivalent to rustc flag) It permits remapping (as a best effort) source path prefixes in all output, including diagnostics, debug information, macro expansions, generated documentation, etc. It takes a value of the form `FROM=TO` where a path prefix equal to `FROM` is rewritten to the value `TO`. #### Example ```sh rustdoc src/lib.rs --remap-path-prefix="$PWD=/foo" ``` ### What isn't stabilized Neither `--remap-path-scope` (~~soon to be added as unstable in `rustdoc`~~ #155451) or the already unstable in `rustc` `documentation` scope are being stabilized or added here. ## Design ### Implementation history - #107099 ### Unresolved questions There are no unresolved questions. ### Post-implementation changes The implementation has evolved with `rustc`, but no changes to the flag it-self have been made. ### Nightly extensions The `documentation` scope, which currently can only be set from `rustc`, as we need to add an equivalent to the `--remap-path-scope` flag, ~~which is planned~~ (EDIT: #155451), but not required, the current `--remap-path-prefix` defaults to the `all` scope, like `rustc`. ### Doors closed We are committing to having to having a flag that permits remapping paths. The compiler team already made the same commitment. ## Feedback ### Call for testing No call for testing has been done. ### Nightly use Unable to determine. A [GitHub search](https://github.com/search?q=%20%2F--remap-path-prefix%2F&type=code) only seems to only reveals the `rustc` usage (over 6k though). Rust-for-Linux is using the [flag](https://github.com/torvalds/linux/blob/e80d033851b3bc94c3d254ac66660ddd0a49d72c/Makefile#L1151-L1153). ## Implementation ### Major parts - #107099 - #149709 - #150172 - #151589 ### Coverage - [`tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs) - [`tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs) - [`tests/rustdoc-ui/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-macro.rs) - [`tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs) - [`tests/rustdoc-ui/lints/remap-path-prefix-lint.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/lints/remap-path-prefix-lint.rs) - [`tests/rustdoc-html/import-remapped-paths.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-html/import-remapped-paths.rs) - [`tests/rustdoc-html/macro/external-macro-src.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-html/macro/external-macro-src.rs) ### Outstanding bugs There are no outstanding bugs regarding `--remap-path-prefix` in `rustdoc`. There are [caveats and limitation](https://doc.rust-lang.org/nightly/rustc/remap-source-paths.html#caveats-and-limitations) in `rustc`, but they mostly concern generated object files, which we don't really have. ### Outstanding FIXMEs There are no FIXME regarding `--remap-path-prefix`. ## Acknowledgments - @edward-shen - @Urgau
2 parents e96c36b + d3bdea1 commit 4d276d7

12 files changed

Lines changed: 34 additions & 30 deletions

src/doc/rustdoc/src/command-line-arguments.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ affect that.
183183
The arguments to this flag are the same as those for the `-C` flag on rustc. Run `rustc -C help` to
184184
get the full list.
185185

186+
## `--remap-path-prefix`: remap source paths in output
187+
188+
This flag is the equivalent flag from `rustc`: `--remap-path-prefix`.
189+
190+
```bash
191+
$ rustdoc src/lib.rs --remap-path-prefix="$PWD=/foo"
192+
```
193+
194+
It permits remapping (as a best effort) source path prefixes in all output, including diagnostics,
195+
debug information, macro expansions, generated documentation, etc. It takes a value of the
196+
form `FROM=TO` where a path prefix equal to `FROM` is rewritten to the value `TO`.
197+
186198
## `--test`: run code examples as tests
187199

188200
Using this flag looks like this:

src/doc/rustdoc/src/unstable-features.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,6 @@ pass `--doctest-build-arg ARG` for each argument `ARG`.
760760

761761
This flag enables the generation of toggles to expand macros in the HTML source code pages.
762762

763-
## `--remap-path-prefix`: Remap source code paths in output
764-
765-
This flag is the equivalent flag from `rustc` `--remap-path-prefix`.
766-
767-
it permits remapping source path prefixes in all output, including compiler diagnostics,
768-
debug information, macro expansions, etc. It takes a value of the form `FROM=TO`
769-
where a path prefix equal to `FROM` is rewritten to the value `TO`.
770-
771763
## `--remap-path-scope`: Scopes to which the source remapping should be done
772764

773765
This flag is the equivalent flag from `rustc` `--remap-path-scope`.

src/librustdoc/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ fn opts() -> Vec<RustcOptGroup> {
458458
By default, it is at `forbid` level.",
459459
"LEVEL",
460460
),
461+
opt(
462+
Stable,
463+
Multi,
464+
"",
465+
"remap-path-prefix",
466+
"Remap source names in compiler messages",
467+
"FROM=TO",
468+
),
461469
opt(Unstable, Opt, "", "index-page", "Markdown file to be used as index page", "PATH"),
462470
opt(
463471
Unstable,
@@ -550,14 +558,6 @@ fn opts() -> Vec<RustcOptGroup> {
550558
"Force all doctests to be compiled as a single binary, instead of one binary per test. If merging fails, rustdoc will emit a hard error.",
551559
"yes|no|auto",
552560
),
553-
opt(
554-
Unstable,
555-
Multi,
556-
"",
557-
"remap-path-prefix",
558-
"Remap source names in compiler messages",
559-
"FROM=TO",
560-
),
561561
opt(
562562
Unstable,
563563
Opt,

tests/run-make/rustdoc-default-output/output-default.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ Options:
125125
Set the most restrictive lint level. More restrictive
126126
lints are capped at this level. By default, it is at
127127
`forbid` level.
128+
--remap-path-prefix FROM=TO
129+
Remap source names in compiler messages
128130
--index-page PATH
129131
Markdown file to be used as index page
130132
--enable-index-page
@@ -158,8 +160,6 @@ Options:
158160
Force all doctests to be compiled as a single binary,
159161
instead of one binary per test. If merging fails,
160162
rustdoc will emit a hard error.
161-
--remap-path-prefix FROM=TO
162-
Remap source names in compiler messages
163163
--remap-path-scope [macro,diagnostics,debuginfo,coverage,object,all]
164164
Defines which scopes of paths should be remapped by
165165
`--remap-path-prefix`

tests/rustdoc-html/auxiliary/remapped-paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags:-Zunstable-options --remap-path-prefix={{src-base}}=
1+
//@ compile-flags:--remap-path-prefix={{src-base}}=
22

33
pub struct MyStruct {
44
field: u32,

tests/rustdoc-ui/lints/remap-path-prefix-lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Regression test for remapped paths in rustdoc errors
22
// <https://github.com/rust-lang/rust/issues/69264>.
33

4-
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path
4+
//@ compile-flags:--remap-path-prefix={{src-base}}=remapped_path
55
//@ rustc-env:RUST_BACKTRACE=0
66

77
#![deny(rustdoc::invalid_html_tags)]

tests/rustdoc-ui/remap-path-prefix-doctest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@ revisions: without-scope
1010

1111
//@ compile-flags:--test --test-args --test-threads=1
12-
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path
12+
//@ compile-flags:--remap-path-prefix={{src-base}}=remapped_path
1313

1414
//@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics
1515
//@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro

tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// adapted to use that, and that normalize line can go away
33

44
//@ failure-status: 101
5-
//@ compile-flags:--test -Z unstable-options --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1
5+
//@ compile-flags:--test --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1
66
//@ rustc-env:RUST_BACKTRACE=0
77
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
88
//@ normalize-stdout: "exit (status|code): 101" -> "exit status: 101"

tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// adapted to use that, and that normalize line can go away
33

44
//@ failure-status: 101
5-
//@ compile-flags:--test -Z unstable-options --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1
5+
//@ compile-flags:--test --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1
66
//@ rustc-env:RUST_BACKTRACE=0
77
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
88

tests/rustdoc-ui/remap-path-prefix-macro-138520.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// when using --remap-path-prefix with macro rendering.
33
// <https://github.com/rust-lang/rust/issues/138520>
44

5-
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path
5+
//@ compile-flags:--remap-path-prefix={{src-base}}=remapped_path
66
//@ rustc-env:RUST_BACKTRACE=0
77
//@ build-pass
88

0 commit comments

Comments
 (0)