| author | bors <bors@rust-lang.org> 2026-05-21 22:46:41 UTC |
| committer | bors <bors@rust-lang.org> 2026-05-21 22:46:41 UTC |
| log | 4d276d7fdba2a24c73dbca3027461bb202e83436 |
| tree | e95f0cc3a6c1f1af54f2b90c5f5c24a5af0ad563 |
| parent | e96c36b6f76833388c519561d145492d2c08db4e |
| parent | d3bdea115d929178e0a3189fb4fdf0e827529ed3 |
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`~~ https://github.com/rust-lang/rust/issues/155451) or the already unstable in `rustc` `documentation` scope are being stabilized or added here.
## Design
### Implementation history
- rust-lang/rust#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: https://github.com/rust-lang/rust/issues/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
- rust-lang/rust#107099
- rust-lang/rust#149709
- rust-lang/rust#150172
- rust-lang/rust#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
12 files changed, 34 insertions(+), 30 deletions(-)
src/doc/rustdoc/src/command-line-arguments.md+12| ... | @@ -183,6 +183,18 @@ affect that. | ... | @@ -183,6 +183,18 @@ affect that. |
| 183 | The arguments to this flag are the same as those for the `-C` flag on rustc. Run `rustc -C help` to | 183 | The arguments to this flag are the same as those for the `-C` flag on rustc. Run `rustc -C help` to |
| 184 | get the full list. | 184 | get the full list. |
| 185 | 185 | ||
| 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 | |||
| 186 | ## `--test`: run code examples as tests | 198 | ## `--test`: run code examples as tests |
| 187 | 199 | ||
| 188 | Using this flag looks like this: | 200 | Using this flag looks like this: |
src/doc/rustdoc/src/unstable-features.md-8| ... | @@ -760,14 +760,6 @@ pass `--doctest-build-arg ARG` for each argument `ARG`. | ... | @@ -760,14 +760,6 @@ pass `--doctest-build-arg ARG` for each argument `ARG`. |
| 760 | 760 | ||
| 761 | This flag enables the generation of toggles to expand macros in the HTML source code pages. | 761 | This flag enables the generation of toggles to expand macros in the HTML source code pages. |
| 762 | 762 | ||
| 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 | |||
| 771 | ## `--remap-path-scope`: Scopes to which the source remapping should be done | 763 | ## `--remap-path-scope`: Scopes to which the source remapping should be done |
| 772 | 764 | ||
| 773 | This flag is the equivalent flag from `rustc` `--remap-path-scope`. | 765 | This flag is the equivalent flag from `rustc` `--remap-path-scope`. |
src/librustdoc/lib.rs+8-8| ... | @@ -458,6 +458,14 @@ fn opts() -> Vec<RustcOptGroup> { | ... | @@ -458,6 +458,14 @@ fn opts() -> Vec<RustcOptGroup> { |
| 458 | By default, it is at `forbid` level.", | 458 | By default, it is at `forbid` level.", |
| 459 | "LEVEL", | 459 | "LEVEL", |
| 460 | ), | 460 | ), |
| 461 | opt( | ||
| 462 | Stable, | ||
| 463 | Multi, | ||
| 464 | "", | ||
| 465 | "remap-path-prefix", | ||
| 466 | "Remap source names in compiler messages", | ||
| 467 | "FROM=TO", | ||
| 468 | ), | ||
| 461 | opt(Unstable, Opt, "", "index-page", "Markdown file to be used as index page", "PATH"), | 469 | opt(Unstable, Opt, "", "index-page", "Markdown file to be used as index page", "PATH"), |
| 462 | opt( | 470 | opt( |
| 463 | Unstable, | 471 | Unstable, |
| ... | @@ -550,14 +558,6 @@ fn opts() -> Vec<RustcOptGroup> { | ... | @@ -550,14 +558,6 @@ fn opts() -> Vec<RustcOptGroup> { |
| 550 | "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.", | 558 | "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.", |
| 551 | "yes|no|auto", | 559 | "yes|no|auto", |
| 552 | ), | 560 | ), |
| 553 | opt( | ||
| 554 | Unstable, | ||
| 555 | Multi, | ||
| 556 | "", | ||
| 557 | "remap-path-prefix", | ||
| 558 | "Remap source names in compiler messages", | ||
| 559 | "FROM=TO", | ||
| 560 | ), | ||
| 561 | opt( | 561 | opt( |
| 562 | Unstable, | 562 | Unstable, |
| 563 | Opt, | 563 | Opt, |
tests/run-make/rustdoc-default-output/output-default.stdout+2-2| ... | @@ -125,6 +125,8 @@ Options: | ... | @@ -125,6 +125,8 @@ Options: |
| 125 | Set the most restrictive lint level. More restrictive | 125 | Set the most restrictive lint level. More restrictive |
| 126 | lints are capped at this level. By default, it is at | 126 | lints are capped at this level. By default, it is at |
| 127 | `forbid` level. | 127 | `forbid` level. |
| 128 | --remap-path-prefix FROM=TO | ||
| 129 | Remap source names in compiler messages | ||
| 128 | --index-page PATH | 130 | --index-page PATH |
| 129 | Markdown file to be used as index page | 131 | Markdown file to be used as index page |
| 130 | --enable-index-page | 132 | --enable-index-page |
| ... | @@ -158,8 +160,6 @@ Options: | ... | @@ -158,8 +160,6 @@ Options: |
| 158 | Force all doctests to be compiled as a single binary, | 160 | Force all doctests to be compiled as a single binary, |
| 159 | instead of one binary per test. If merging fails, | 161 | instead of one binary per test. If merging fails, |
| 160 | rustdoc will emit a hard error. | 162 | rustdoc will emit a hard error. |
| 161 | --remap-path-prefix FROM=TO | ||
| 162 | Remap source names in compiler messages | ||
| 163 | --remap-path-scope [macro,diagnostics,debuginfo,coverage,object,all] | 163 | --remap-path-scope [macro,diagnostics,debuginfo,coverage,object,all] |
| 164 | Defines which scopes of paths should be remapped by | 164 | Defines which scopes of paths should be remapped by |
| 165 | `--remap-path-prefix` | 165 | `--remap-path-prefix` |
tests/rustdoc-html/auxiliary/remapped-paths.rs+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | //@ compile-flags:-Zunstable-options --remap-path-prefix={{src-base}}= | 1 | //@ compile-flags:--remap-path-prefix={{src-base}}= |
| 2 | 2 | ||
| 3 | pub struct MyStruct { | 3 | pub struct MyStruct { |
| 4 | field: u32, | 4 | field: u32, |
tests/rustdoc-ui/lints/remap-path-prefix-lint.rs+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | // Regression test for remapped paths in rustdoc errors | 1 | // Regression test for remapped paths in rustdoc errors |
| 2 | // <https://github.com/rust-lang/rust/issues/69264>. | 2 | // <https://github.com/rust-lang/rust/issues/69264>. |
| 3 | 3 | ||
| 4 | //@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path | 4 | //@ compile-flags:--remap-path-prefix={{src-base}}=remapped_path |
| 5 | //@ rustc-env:RUST_BACKTRACE=0 | 5 | //@ rustc-env:RUST_BACKTRACE=0 |
| 6 | 6 | ||
| 7 | #![deny(rustdoc::invalid_html_tags)] | 7 | #![deny(rustdoc::invalid_html_tags)] |
tests/rustdoc-ui/remap-path-prefix-doctest.rs+1-1| ... | @@ -9,7 +9,7 @@ | ... | @@ -9,7 +9,7 @@ |
| 9 | //@ revisions: without-scope | 9 | //@ revisions: without-scope |
| 10 | 10 | ||
| 11 | //@ compile-flags:--test --test-args --test-threads=1 | 11 | //@ 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 |
| 13 | 13 | ||
| 14 | //@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics | 14 | //@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics |
| 15 | //@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro | 15 | //@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro |
tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs+1-1| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | // adapted to use that, and that normalize line can go away | 2 | // adapted to use that, and that normalize line can go away |
| 3 | 3 | ||
| 4 | //@ failure-status: 101 | 4 | //@ 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 |
| 6 | //@ rustc-env:RUST_BACKTRACE=0 | 6 | //@ rustc-env:RUST_BACKTRACE=0 |
| 7 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | 7 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" |
| 8 | //@ normalize-stdout: "exit (status|code): 101" -> "exit status: 101" | 8 | //@ normalize-stdout: "exit (status|code): 101" -> "exit status: 101" |
tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs+1-1| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | // adapted to use that, and that normalize line can go away | 2 | // adapted to use that, and that normalize line can go away |
| 3 | 3 | ||
| 4 | //@ failure-status: 101 | 4 | //@ 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 |
| 6 | //@ rustc-env:RUST_BACKTRACE=0 | 6 | //@ rustc-env:RUST_BACKTRACE=0 |
| 7 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | 7 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" |
| 8 | 8 |
tests/rustdoc-ui/remap-path-prefix-macro-138520.rs+1-1| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | // when using --remap-path-prefix with macro rendering. | 2 | // when using --remap-path-prefix with macro rendering. |
| 3 | // <https://github.com/rust-lang/rust/issues/138520> | 3 | // <https://github.com/rust-lang/rust/issues/138520> |
| 4 | 4 | ||
| 5 | //@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path | 5 | //@ compile-flags:--remap-path-prefix={{src-base}}=remapped_path |
| 6 | //@ rustc-env:RUST_BACKTRACE=0 | 6 | //@ rustc-env:RUST_BACKTRACE=0 |
| 7 | //@ build-pass | 7 | //@ build-pass |
| 8 | 8 |
tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs+1-1| ... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
| 4 | // FIXME: if/when the output of the test harness can be tested on its own, this test should be | 4 | // FIXME: if/when the output of the test harness can be tested on its own, this test should be |
| 5 | // adapted to use that, and that normalize line can go away | 5 | // adapted to use that, and that normalize line can go away |
| 6 | 6 | ||
| 7 | //@ compile-flags:--test -Z unstable-options --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1 | 7 | //@ compile-flags:--test --remap-path-prefix={{src-base}}=remapped_path --test-args --test-threads=1 |
| 8 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | 8 | //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" |
| 9 | 9 | ||
| 10 | // doctest passes at runtime | 10 | // doctest passes at runtime |
tests/rustdoc-ui/remap-path-prefix.rs+5-5| ... | @@ -7,11 +7,11 @@ | ... | @@ -7,11 +7,11 @@ |
| 7 | //@ revisions: with-diag-scope with-macro-scope with-debuginfo-scope with-doc-scope | 7 | //@ revisions: with-diag-scope with-macro-scope with-debuginfo-scope with-doc-scope |
| 8 | //@ revisions: without-scopes without-remap | 8 | //@ revisions: without-scopes without-remap |
| 9 | 9 | ||
| 10 | //@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped | 10 | //@[with-diag-scope] compile-flags: --remap-path-prefix={{src-base}}=remapped |
| 11 | //@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped | 11 | //@[with-macro-scope] compile-flags: --remap-path-prefix={{src-base}}=remapped |
| 12 | //@[with-debuginfo-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped | 12 | //@[with-debuginfo-scope] compile-flags: --remap-path-prefix={{src-base}}=remapped |
| 13 | //@[with-doc-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped | 13 | //@[with-doc-scope] compile-flags: --remap-path-prefix={{src-base}}=remapped |
| 14 | //@[without-scopes] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped | 14 | //@[without-scopes] compile-flags: --remap-path-prefix={{src-base}}=remapped |
| 15 | 15 | ||
| 16 | //@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics | 16 | //@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics |
| 17 | //@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro | 17 | //@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro |