Skip to content

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Oct 12, 2025

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:

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
  • object - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for macro,debuginfo.
  • all (default) - an alias for all of the above, also equivalent to supplying only --remap-path-prefix without --remap-path-scope.

Example

# 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

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.

Implementation

Major parts

  • pub struct RemapPathScopeComponents: u8 {
    /// Apply remappings to the expansion of std::file!() macro
    const MACRO = 1 << 0;
    /// Apply remappings to printed compiler diagnostics
    const DIAGNOSTICS = 1 << 1;
    /// Apply remappings to debug information
    const DEBUGINFO = 1 << 3;
    /// An alias for `macro` and `debuginfo`. This ensures all paths in compiled
    /// executables or libraries are remapped but not elsewhere.
    const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits();
    }
  • fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_>;
  • pub enum FileNameEmbeddablePreference {
    /// If a remapped path is available, only embed the `virtual_path` and omit the `local_path`.
    ///
    /// Otherwise embed the local-path into the `virtual_path`.
    RemappedOnly,
    /// Embed the original path as well as its remapped `virtual_path` component if available.
    LocalAndRemapped,
    }
    #[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
    pub enum FileNameDisplayPreference {
    /// Display the path after the application of rewrite rules provided via `--remap-path-prefix`.
    /// This is appropriate for paths that get embedded into files produced by the compiler.
    Remapped,
    /// Display the path before the application of rewrite rules provided via `--remap-path-prefix`.
    /// This is appropriate for use in user-facing output (such as diagnostics).
    Local,
    /// Display only the filename, as a way to reduce the verbosity of the output.
    /// This is appropriate for use in user-facing output (such as diagnostics).
    Short,
    }

Coverage

Outstanding bugs

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

There are 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.

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.

@rustbot labels +T-compiler +needs-fcp +F-trim-paths
r? @davidtwco

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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. F-trim-paths Feature: trim-paths needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Oct 12, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for driving the stabilization!

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

"There are no outstanding bugs" probably?

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.

Don't want to block the stabilization. However, this sounds a bit odd that there is no major use cases beyond Cargo and rustc is heading toward stabilization alone. That may imply t-cargo should review again whether --remap-path-scope is useful and cover what they want at least (of course this is on me as I worked on Cargo side of this)

Copy link
Member Author

Choose a reason for hiding this comment

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

"There are no outstanding bugs" probably?

As far as I know --remap-path-scope has no bugs. We have test for all the scopes, with/without dependency and with mixed scopes between crates.

However, this sounds a bit odd that there is no major use cases beyond Cargo and rustc is heading toward stabilization alone.

It doesn't really surprises me that there are no public use of it. It's quite a pain currently to setup --remap-path-prefix and -Zremap-path-scope in Cargo, as there is currently no support for it, which is what we are trying to solve. I suspect most users are using RUSTFLAGS which I don't think is typically committed.

That may imply t-cargo should review again whether --remap-path-scope is useful

Well, be able to see the not-remapped paths in diagnostics is quite nice thing.

The RFC specifically states that the default should be object for the release profile.

Copy link
Member

Choose a reason for hiding this comment

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

"There are no outstanding bugs" probably?

I meant the "no" is missing in the original PR description.

@Urgau Urgau force-pushed the stablize-remap-path-scope branch from ac9448d to bcbf54a Compare October 12, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs F-trim-paths Feature: trim-paths needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants