Skip to content

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented Mar 13, 2024

This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in #111540 (comment).

And also do some correctness fixes found during the review.

cc @weihanglo
r? @michaelwoerister

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 13, 2024
@michaelwoerister
Copy link
Member

Thanks for the PR, @Urgau! I think we'll do this, but since this is deviating from the accepted RFC, I want to find out what the procedure is here.

@Urgau
Copy link
Member Author

Urgau commented Mar 14, 2024

I think we'll do this, but since this is deviating from the accepted RFC, I want to find out what the procedure is here.

I'm not aware of such procedure. Our RFCs are not normative and it's common to diverged from them in the implementation and experimentation phase.

I would say that as long as we respect the goal of the RFC (as defined in the Summary and Motivation section of the RFC), we are good to adapt the implementation to achieve that goal, particularly here since we are adapting the implementation to match the reality (ie. the current limitation of the tooling and LLVM).

There is also nothing here that would prevent re-introducing the lost options in the future.

So I think we are go to go.

@michaelwoerister
Copy link
Member

I actually remembered a similar case where I asked about the proceduce:
https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Add.20-C.20dlltool.20for.20raw-dylibs.3F

Let's make sure we document what we are doing on the tracking issue an mention it in the stabilization FCP, then we should indeed be good.

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch from 23601a6 to 84e54cd Compare March 15, 2024 17:25
@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch from 84e54cd to e4a6f48 Compare March 18, 2024 18:39
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2024

Some changes occurred in coverage instrumentation.

cc @Zalathar

Some changes occurred in run-make tests.

cc @jieyouxu

Some changes occurred in coverage instrumentation.

cc @Zalathar

@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch 2 times, most recently from 4cfbe65 to fe8e0d6 Compare March 18, 2024 20:43
@bors
Copy link
Collaborator

bors commented Mar 19, 2024

☔ The latest upstream changes (presumably #122713) made this pull request unmergeable. Please resolve the merge conflicts.

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch from fe8e0d6 to e12220d Compare March 19, 2024 07:00
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch from 6e19ace to 342e15d Compare March 19, 2024 12:42
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Mar 19, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 19, 2024

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@Urgau Urgau force-pushed the simplify-trim-paths-feature branch from f2a2c4c to fefb8f1 Compare March 28, 2024 17:51
@Urgau
Copy link
Member Author

Urgau commented Mar 28, 2024

Rebased (and fix some typos).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 28, 2024
@michaelwoerister
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 29, 2024

📌 Commit fefb8f1 has been approved by michaelwoerister

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2024
@bors
Copy link
Collaborator

bors commented Mar 29, 2024

⌛ Testing commit fefb8f1 with merge 685927a...

@bors
Copy link
Collaborator

bors commented Mar 29, 2024

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 685927a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 29, 2024
@bors bors merged commit 685927a into rust-lang:master Mar 29, 2024
@rustbot rustbot added this to the 1.79.0 milestone Mar 29, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (685927a): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 668.043s -> 667.959s (-0.01%)
Artifact size: 315.85 MiB -> 315.84 MiB (-0.00%)

bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Apr 5, 2024
…=michaelwoerister

Simplify trim-paths feature by merging all debuginfo options together

This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in rust-lang#111540 (comment).

And also do some correctness fixes found during the review.

cc `@weihanglo`
r? `@michaelwoerister`
smoelius added a commit to trailofbits/dylint that referenced this pull request Apr 7, 2024
github-merge-queue bot pushed a commit to trailofbits/dylint that referenced this pull request Apr 7, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 20, 2026
…twco

Stabilize `-Zremap-path-scope`

# Stabilization report of `--remap-path-scope`

## Summary

RFC 3127 trim-paths aims to improve the current status of sanitizing paths emitted by the compiler via the `--remap-path-prefix=FROM=TO` command line flag, by offering a profile setting named `trim-paths` in Cargo to sanitize absolute paths introduced during compilation that may be embedded in the compiled binary executable or library.

As part of that RFC the compiler was asked to add the `--remap-path-scope` command-line flag to control the scoping of how paths get remapped in the resulting binary.

Tracking:

- rust-lang#111540

### What is stabilized

The rustc `--remap-path-scope` flag is being stabilized by this PR. It defines which scopes of paths should be remapped by `--remap-path-prefix`.

This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.

The valid scopes are:

- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
- `diagnostics` - apply remappings to printed compiler diagnostics
- `debuginfo` - apply remappings to debug informations
- `coverage` - apply remappings to coverage informations
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.

#### Example

```sh
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
```

### What isn't stabilized

None of the Cargo facility is being stabilized in this stabilization PR, only the `--remap-path-scope` flag in `rustc` is being stabilized.

## Design

### RFC history

- [RFC3127 - trim-paths](https://rust-lang.github.io/rfcs/3127-trim-paths.html)

### Answers to unresolved questions

> What questions were left unresolved by the RFC? How have they been answered? Link to any relevant lang decisions.

There are no unresolved questions regarding `--remap-path-scope`.

(The tracking issue list a bunch of unresolved questions but they are for `--remap-path-prefix` or the bigger picture `trim-paths` in Cargo and are not related the functionality provided by `--remap-path-scope`.)

### Post-RFC changes

The RFC described more scopes, in particularly regarding split debuginfo. Those scopes where removed after analysis by `michaelwoerister` of all the possible combinations in rust-lang#111540 (comment).

### Nightly extensions

There are no nightly extensions.

### Doors closed

We are committing to having to having a flag that control which paths are being remapped based on a "scope".

## Feedback

### Call for testing

> Has a "call for testing" been done? If so, what feedback was received?

No call for testing has been done per se but feedback has been received on both the rust-lang/rust and rust-lang/cargo tracking issue.

The feedback was mainly related to deficiencies in *our best-effort* `--remap-path-prefix` implementation, in particular regarding linkers added paths, which does not change anything for `--remap-path-scope`.

### Nightly use

> Do any known nightly users use this feature? Counting instances of `#![feature(FEATURE_NAME)]` on GitHub with grep might be informative.

Except for Cargo unstable `trim-paths` there doesn't appear any committed use [on GitHub](https://github.com/search?q=%22--remap-path-scope%22+NOT+path%3A%2F%5Esrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F+NOT+path%3A%2F%5Etext%5C%2F%2F+NOT+path%3A%2F%5Erust%5C%2Fsrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Ecollector%5C%2Fcompile-benchmarks%5C%2Fcargo-0%5C.87%5C.1%5C%2Fsrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F&type=code).

## Implementation

### Major parts

- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/config.rs#L1373-L1384
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/session.rs#L1526
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_span/src/lib.rs#L352-L372

### Coverage

- [`tests/run-make/split-debuginfo/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/split-debuginfo/rmake.rs#L7)
- [`tests/ui/errors/remap-path-prefix.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix.rs#L4)
- [`tests/ui/errors/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-macro.rs#L1-L4)
- [`tests/run-make/remap-path-prefix-dwarf/rmake.rs
`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix-dwarf/rmake.rs)
- [`tests/run-make/remap-path-prefix/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix/rmake.rs)
- [`tests/ui/errors/remap-path-prefix-diagnostics.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-diagnostics.rs)

### Outstanding bugs

> What outstanding bugs involve this feature? List them. Should any block the stabilization? Discuss why or why not.

There are no outstanding bugs regarding `--remap-path-scope`.

### Outstanding FIXMEs

> What FIXMEs are still in the code for that feature and why is it OK to leave them there?

There are no FIXME regarding `--remap-path-scope` in it-self.

### Tool changes

> What changes must be made to our other tools to support this feature. Has this work been done? Link to any relevant PRs and issues.

- rustdoc (both JSON, HTML and doctest)
  - `rustdoc` has support for `--remap-path-prefix`, it should probably also get support for `--remap-path-scope`, although rustdoc maybe want to adapt the scopes for it's use (replace `debuginfo` with `documentation` for example).

## History

> List issues and PRs that are important for understanding how we got here.

- rust-lang#115214
- rust-lang#122450
- rust-lang#139550
- rust-lang#140716

## Acknowledgments

> Summarize contributors to the feature by name for recognition and so that those people are notified about the stabilization. Does anyone who worked on this *not* think it should be stabilized right now? We'd like to hear about that if so.

- @cbeuw
- @michaelwoerister
- @weihanglo
- @Urgau

@rustbot labels +T-compiler +needs-fcp +F-trim-paths
r? @davidtwco
rust-timer added a commit that referenced this pull request Jan 20, 2026
Rollup merge of #147611 - stablize-remap-path-scope, r=davidtwco

Stabilize `-Zremap-path-scope`

# Stabilization report of `--remap-path-scope`

## Summary

RFC 3127 trim-paths aims to improve the current status of sanitizing paths emitted by the compiler via the `--remap-path-prefix=FROM=TO` command line flag, by offering a profile setting named `trim-paths` in Cargo to sanitize absolute paths introduced during compilation that may be embedded in the compiled binary executable or library.

As part of that RFC the compiler was asked to add the `--remap-path-scope` command-line flag to control the scoping of how paths get remapped in the resulting binary.

Tracking:

- #111540

### What is stabilized

The rustc `--remap-path-scope` flag is being stabilized by this PR. It defines which scopes of paths should be remapped by `--remap-path-prefix`.

This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.

The valid scopes are:

- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
- `diagnostics` - apply remappings to printed compiler diagnostics
- `debuginfo` - apply remappings to debug informations
- `coverage` - apply remappings to coverage informations
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.

#### Example

```sh
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
```

### What isn't stabilized

None of the Cargo facility is being stabilized in this stabilization PR, only the `--remap-path-scope` flag in `rustc` is being stabilized.

## Design

### RFC history

- [RFC3127 - trim-paths](https://rust-lang.github.io/rfcs/3127-trim-paths.html)

### Answers to unresolved questions

> What questions were left unresolved by the RFC? How have they been answered? Link to any relevant lang decisions.

There are no unresolved questions regarding `--remap-path-scope`.

(The tracking issue list a bunch of unresolved questions but they are for `--remap-path-prefix` or the bigger picture `trim-paths` in Cargo and are not related the functionality provided by `--remap-path-scope`.)

### Post-RFC changes

The RFC described more scopes, in particularly regarding split debuginfo. Those scopes where removed after analysis by `michaelwoerister` of all the possible combinations in #111540 (comment).

### Nightly extensions

There are no nightly extensions.

### Doors closed

We are committing to having to having a flag that control which paths are being remapped based on a "scope".

## Feedback

### Call for testing

> Has a "call for testing" been done? If so, what feedback was received?

No call for testing has been done per se but feedback has been received on both the rust-lang/rust and rust-lang/cargo tracking issue.

The feedback was mainly related to deficiencies in *our best-effort* `--remap-path-prefix` implementation, in particular regarding linkers added paths, which does not change anything for `--remap-path-scope`.

### Nightly use

> Do any known nightly users use this feature? Counting instances of `#![feature(FEATURE_NAME)]` on GitHub with grep might be informative.

Except for Cargo unstable `trim-paths` there doesn't appear any committed use [on GitHub](https://github.com/search?q=%22--remap-path-scope%22+NOT+path%3A%2F%5Esrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F+NOT+path%3A%2F%5Etext%5C%2F%2F+NOT+path%3A%2F%5Erust%5C%2Fsrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Ecollector%5C%2Fcompile-benchmarks%5C%2Fcargo-0%5C.87%5C.1%5C%2Fsrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F&type=code).

## Implementation

### Major parts

- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/config.rs#L1373-L1384
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/session.rs#L1526
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_span/src/lib.rs#L352-L372

### Coverage

- [`tests/run-make/split-debuginfo/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/split-debuginfo/rmake.rs#L7)
- [`tests/ui/errors/remap-path-prefix.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix.rs#L4)
- [`tests/ui/errors/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-macro.rs#L1-L4)
- [`tests/run-make/remap-path-prefix-dwarf/rmake.rs
`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix-dwarf/rmake.rs)
- [`tests/run-make/remap-path-prefix/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix/rmake.rs)
- [`tests/ui/errors/remap-path-prefix-diagnostics.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-diagnostics.rs)

### Outstanding bugs

> What outstanding bugs involve this feature? List them. Should any block the stabilization? Discuss why or why not.

There are no outstanding bugs regarding `--remap-path-scope`.

### Outstanding FIXMEs

> What FIXMEs are still in the code for that feature and why is it OK to leave them there?

There are no FIXME regarding `--remap-path-scope` in it-self.

### Tool changes

> What changes must be made to our other tools to support this feature. Has this work been done? Link to any relevant PRs and issues.

- rustdoc (both JSON, HTML and doctest)
  - `rustdoc` has support for `--remap-path-prefix`, it should probably also get support for `--remap-path-scope`, although rustdoc maybe want to adapt the scopes for it's use (replace `debuginfo` with `documentation` for example).

## History

> List issues and PRs that are important for understanding how we got here.

- #115214
- #122450
- #139550
- #140716

## Acknowledgments

> Summarize contributors to the feature by name for recognition and so that those people are notified about the stabilization. Does anyone who worked on this *not* think it should be stabilized right now? We'd like to hear about that if so.

- @cbeuw
- @michaelwoerister
- @weihanglo
- @Urgau

@rustbot labels +T-compiler +needs-fcp +F-trim-paths
r? @davidtwco
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 20, 2026
Stabilize `-Zremap-path-scope`

# Stabilization report of `--remap-path-scope`

## Summary

RFC 3127 trim-paths aims to improve the current status of sanitizing paths emitted by the compiler via the `--remap-path-prefix=FROM=TO` command line flag, by offering a profile setting named `trim-paths` in Cargo to sanitize absolute paths introduced during compilation that may be embedded in the compiled binary executable or library.

As part of that RFC the compiler was asked to add the `--remap-path-scope` command-line flag to control the scoping of how paths get remapped in the resulting binary.

Tracking:

- rust-lang/rust#111540

### What is stabilized

The rustc `--remap-path-scope` flag is being stabilized by this PR. It defines which scopes of paths should be remapped by `--remap-path-prefix`.

This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.

The valid scopes are:

- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
- `diagnostics` - apply remappings to printed compiler diagnostics
- `debuginfo` - apply remappings to debug informations
- `coverage` - apply remappings to coverage informations
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.

#### Example

```sh
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
```

### What isn't stabilized

None of the Cargo facility is being stabilized in this stabilization PR, only the `--remap-path-scope` flag in `rustc` is being stabilized.

## Design

### RFC history

- [RFC3127 - trim-paths](https://rust-lang.github.io/rfcs/3127-trim-paths.html)

### Answers to unresolved questions

> What questions were left unresolved by the RFC? How have they been answered? Link to any relevant lang decisions.

There are no unresolved questions regarding `--remap-path-scope`.

(The tracking issue list a bunch of unresolved questions but they are for `--remap-path-prefix` or the bigger picture `trim-paths` in Cargo and are not related the functionality provided by `--remap-path-scope`.)

### Post-RFC changes

The RFC described more scopes, in particularly regarding split debuginfo. Those scopes where removed after analysis by `michaelwoerister` of all the possible combinations in rust-lang/rust#111540 (comment).

### Nightly extensions

There are no nightly extensions.

### Doors closed

We are committing to having to having a flag that control which paths are being remapped based on a "scope".

## Feedback

### Call for testing

> Has a "call for testing" been done? If so, what feedback was received?

No call for testing has been done per se but feedback has been received on both the rust-lang/rust and rust-lang/cargo tracking issue.

The feedback was mainly related to deficiencies in *our best-effort* `--remap-path-prefix` implementation, in particular regarding linkers added paths, which does not change anything for `--remap-path-scope`.

### Nightly use

> Do any known nightly users use this feature? Counting instances of `#![feature(FEATURE_NAME)]` on GitHub with grep might be informative.

Except for Cargo unstable `trim-paths` there doesn't appear any committed use [on GitHub](https://github.com/search?q=%22--remap-path-scope%22+NOT+path%3A%2F%5Esrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F+NOT+path%3A%2F%5Etext%5C%2F%2F+NOT+path%3A%2F%5Erust%5C%2Fsrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Ecollector%5C%2Fcompile-benchmarks%5C%2Fcargo-0%5C.87%5C.1%5C%2Fsrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F&type=code).

## Implementation

### Major parts

- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/config.rs#L1373-L1384
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/session.rs#L1526
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_span/src/lib.rs#L352-L372

### Coverage

- [`tests/run-make/split-debuginfo/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/split-debuginfo/rmake.rs#L7)
- [`tests/ui/errors/remap-path-prefix.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix.rs#L4)
- [`tests/ui/errors/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-macro.rs#L1-L4)
- [`tests/run-make/remap-path-prefix-dwarf/rmake.rs
`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix-dwarf/rmake.rs)
- [`tests/run-make/remap-path-prefix/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix/rmake.rs)
- [`tests/ui/errors/remap-path-prefix-diagnostics.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-diagnostics.rs)

### Outstanding bugs

> What outstanding bugs involve this feature? List them. Should any block the stabilization? Discuss why or why not.

There are no outstanding bugs regarding `--remap-path-scope`.

### Outstanding FIXMEs

> What FIXMEs are still in the code for that feature and why is it OK to leave them there?

There are no FIXME regarding `--remap-path-scope` in it-self.

### Tool changes

> What changes must be made to our other tools to support this feature. Has this work been done? Link to any relevant PRs and issues.

- rustdoc (both JSON, HTML and doctest)
  - `rustdoc` has support for `--remap-path-prefix`, it should probably also get support for `--remap-path-scope`, although rustdoc maybe want to adapt the scopes for it's use (replace `debuginfo` with `documentation` for example).

## History

> List issues and PRs that are important for understanding how we got here.

- rust-lang/rust#115214
- rust-lang/rust#122450
- rust-lang/rust#139550
- rust-lang/rust#140716

## Acknowledgments

> Summarize contributors to the feature by name for recognition and so that those people are notified about the stabilization. Does anyone who worked on this *not* think it should be stabilized right now? We'd like to hear about that if so.

- @cbeuw
- @michaelwoerister
- @weihanglo
- @Urgau

@rustbot labels +T-compiler +needs-fcp +F-trim-paths
r? @davidtwco
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 21, 2026
Stabilize `-Zremap-path-scope`

# Stabilization report of `--remap-path-scope`

## Summary

RFC 3127 trim-paths aims to improve the current status of sanitizing paths emitted by the compiler via the `--remap-path-prefix=FROM=TO` command line flag, by offering a profile setting named `trim-paths` in Cargo to sanitize absolute paths introduced during compilation that may be embedded in the compiled binary executable or library.

As part of that RFC the compiler was asked to add the `--remap-path-scope` command-line flag to control the scoping of how paths get remapped in the resulting binary.

Tracking:

- rust-lang/rust#111540

### What is stabilized

The rustc `--remap-path-scope` flag is being stabilized by this PR. It defines which scopes of paths should be remapped by `--remap-path-prefix`.

This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.

The valid scopes are:

- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
- `diagnostics` - apply remappings to printed compiler diagnostics
- `debuginfo` - apply remappings to debug informations
- `coverage` - apply remappings to coverage informations
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.

#### Example

```sh
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
```

### What isn't stabilized

None of the Cargo facility is being stabilized in this stabilization PR, only the `--remap-path-scope` flag in `rustc` is being stabilized.

## Design

### RFC history

- [RFC3127 - trim-paths](https://rust-lang.github.io/rfcs/3127-trim-paths.html)

### Answers to unresolved questions

> What questions were left unresolved by the RFC? How have they been answered? Link to any relevant lang decisions.

There are no unresolved questions regarding `--remap-path-scope`.

(The tracking issue list a bunch of unresolved questions but they are for `--remap-path-prefix` or the bigger picture `trim-paths` in Cargo and are not related the functionality provided by `--remap-path-scope`.)

### Post-RFC changes

The RFC described more scopes, in particularly regarding split debuginfo. Those scopes where removed after analysis by `michaelwoerister` of all the possible combinations in rust-lang/rust#111540 (comment).

### Nightly extensions

There are no nightly extensions.

### Doors closed

We are committing to having to having a flag that control which paths are being remapped based on a "scope".

## Feedback

### Call for testing

> Has a "call for testing" been done? If so, what feedback was received?

No call for testing has been done per se but feedback has been received on both the rust-lang/rust and rust-lang/cargo tracking issue.

The feedback was mainly related to deficiencies in *our best-effort* `--remap-path-prefix` implementation, in particular regarding linkers added paths, which does not change anything for `--remap-path-scope`.

### Nightly use

> Do any known nightly users use this feature? Counting instances of `#![feature(FEATURE_NAME)]` on GitHub with grep might be informative.

Except for Cargo unstable `trim-paths` there doesn't appear any committed use [on GitHub](https://github.com/search?q=%22--remap-path-scope%22+NOT+path%3A%2F%5Esrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F+NOT+path%3A%2F%5Etext%5C%2F%2F+NOT+path%3A%2F%5Erust%5C%2Fsrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Funstable-book%5C%2Fsrc%5C%2Fcompiler-flags%5C%2F%2F+NOT+path%3A%2F%5Ecollector%5C%2Fcompile-benchmarks%5C%2Fcargo-0%5C.87%5C.1%5C%2Fsrc%5C%2Fcargo%5C%2Fcore%5C%2Fcompiler%5C%2F%2F&type=code).

## Implementation

### Major parts

- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/config.rs#L1373-L1384
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_session/src/session.rs#L1526
- https://github.com/rust-lang/rust/blob/b3f8586fb1e4859678d6b231e780ff81801d2282/compiler/rustc_span/src/lib.rs#L352-L372

### Coverage

- [`tests/run-make/split-debuginfo/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/split-debuginfo/rmake.rs#L7)
- [`tests/ui/errors/remap-path-prefix.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix.rs#L4)
- [`tests/ui/errors/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-macro.rs#L1-L4)
- [`tests/run-make/remap-path-prefix-dwarf/rmake.rs
`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix-dwarf/rmake.rs)
- [`tests/run-make/remap-path-prefix/rmake.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/run-make/remap-path-prefix/rmake.rs)
- [`tests/ui/errors/remap-path-prefix-diagnostics.rs`](https://github.com/rust-lang/rust/blob/9725c4baacef19345e13f91b27e66e10ef5592ae/tests/ui/errors/remap-path-prefix-diagnostics.rs)

### Outstanding bugs

> What outstanding bugs involve this feature? List them. Should any block the stabilization? Discuss why or why not.

There are no outstanding bugs regarding `--remap-path-scope`.

### Outstanding FIXMEs

> What FIXMEs are still in the code for that feature and why is it OK to leave them there?

There are no FIXME regarding `--remap-path-scope` in it-self.

### Tool changes

> What changes must be made to our other tools to support this feature. Has this work been done? Link to any relevant PRs and issues.

- rustdoc (both JSON, HTML and doctest)
  - `rustdoc` has support for `--remap-path-prefix`, it should probably also get support for `--remap-path-scope`, although rustdoc maybe want to adapt the scopes for it's use (replace `debuginfo` with `documentation` for example).

## History

> List issues and PRs that are important for understanding how we got here.

- rust-lang/rust#115214
- rust-lang/rust#122450
- rust-lang/rust#139550
- rust-lang/rust#140716

## Acknowledgments

> Summarize contributors to the feature by name for recognition and so that those people are notified about the stabilization. Does anyone who worked on this *not* think it should be stabilized right now? We'd like to hear about that if so.

- @cbeuw
- @michaelwoerister
- @weihanglo
- @Urgau

@rustbot labels +T-compiler +needs-fcp +F-trim-paths
r? @davidtwco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants