Skip to content

fix(trim-paths)!: limit options to none|object|all - #17432

Merged
epage merged 4 commits into
rust-lang:masterfrom
weihanglo:only-object-scope
Sep 4, 2026
Merged

fix(trim-paths)!: limit options to none|object|all#17432
epage merged 4 commits into
rust-lang:masterfrom
weihanglo:only-object-scope

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

This limits profile trim-paths options to only none, object, and all.
For other scopes and boolean values, we can add it in the future when needed.

This is a stabilization preparation for -Ztrim-paths.
See #12137 (comment).

How to test and review this PR?

Also rewrote the profile trim-paths doc a bit but not extremely satisfied.
Please help proofread.

@weihanglo weihanglo added the Z-trim-paths Nightly: path sanitization label Sep 3, 2026
@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2026
@rustbot

rustbot commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo

Comment on lines +1658 to 1661
> [!NOTE]
> For forward compatibility,
> build scripts should accept a comma-separated list of scopes.
* `CARGO_TRIM_PATHS_REMAP` --- The `<from>=<to>` path remap pairs Cargo passes to the compiler,

@epage epage Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aside: do we support this yet in build-rs?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure! I am still thinking about a reasonable API.

My hope is that popular helper build dep dependencies use them, like cc-rs which already supports. Application build scripts likely don't need this. cc-rs likely has covered 95% of the use cases (including cmake-rs which takes cc-rs as a dependency).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Tracked in #12137

Comment thread doc/book/src/reference/unstable.md Outdated
Comment on lines +1519 to +1525
`trim-paths` is a profile setting which enables and controls the sanitization of file paths in build outputs.
It takes the following values:

- `"none"` --- disable path sanitization
- `"macro"` --- sanitize paths in the expansion of `std::file!()` macro.
This is where paths in embedded panic messages come from
- `"diagnostics"` --- sanitize paths in printed compiler diagnostics
- `"object"` --- sanitize paths in compiled executables or libraries
- `"all"` --- sanitize paths in all possible locations
The `trim-paths` option controls path sanitization in build outputs.
It uses rustc's [`--remap-path-scope`] to control the scope where paths are sanitized,
while Cargo supplies the path-prefix mappings described in the [remapping rules].

It also takes an array with the combinations of `"macro"`, `"diagnostics"`, and `"object"`.
The valid options are `"none"`, `"object"`, and `"all"`.
`"none"` disables sanitization.
The other values select the corresponding rustc remapping scope.

@epage epage Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like we are removing the docs that distinguish between object and all

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried to minimize this to avoid duplicating docs on rustc side. Oour profile doc is mixed. For strip and split-debuginfo we don't have docs for each, while for debug and opt-level we do enumerate them. Do you think this worth explicit docs and also talking about use cases in Cargo doc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, after reading other comments

I think we should have some minimal docs for each options, which I think can address most of doc issues.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated. I hope that clarifies things.

Comment thread doc/book/src/reference/unstable.md Outdated
This is where paths in embedded panic messages come from
- `"diagnostics"` --- sanitize paths in printed compiler diagnostics
- `"object"` --- sanitize paths in compiled executables or libraries
- `"all"` --- sanitize paths in all possible locations

@epage epage Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does r-a or any other tool need a heads up that with all, diagnostics won't point to valid files?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should document issue and perhaps put a warning as precaution. And yes good idea when stabilizing we should let tool authors know about it

Comment thread doc/book/src/reference/unstable.md Outdated
while Cargo supplies the path-prefix mappings described in the [remapping rules].

It also takes an array with the combinations of `"macro"`, `"diagnostics"`, and `"object"`.
The valid options are `"none"`, `"object"`, and `"all"`.

@epage epage Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're looking to drop things, what are the use cases for having both object and all?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

object, like you have mentioned, preserves certain debuggability and local development experience.

all is more fore hermetic builds to sanitize as many locations as possible. One of the biggest difference is metadata output. Metadadta in in dylib and proc-macors are only remapped in the all scope. When I test this with some caching service, without remapping all for proc-macros, the artifact checksum mismatches and cache missed. See rust-lang/rust#159621

@rustbot

rustbot commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@epage
epage added this pull request to the merge queue Sep 4, 2026
Merged via the queue into rust-lang:master with commit 3c0b534 Sep 4, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 4, 2026
@weihanglo
weihanglo deleted the only-object-scope branch September 4, 2026 17:44
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 5, 2026
Update cargo submodule

9 commits in b2e9d5f9db3fb1c454ab84f10c16508984a266e2..3c0b534756e166d12eb9fd2e1abfe5b42ac6101e
2026-09-02 14:49:16 +0000 to 2026-09-04 17:03:10 +0000
- fix(trim-paths)!: limit options to `none|object|all` (rust-lang/cargo#17432)
- fix(git): Apply pr hint to git-fetch-with-cli (rust-lang/cargo#17437)
- fix(git): Make PR dep note cloer to our style guide (rust-lang/cargo#17436)
- docs: clarify cargo vendor source config option (rust-lang/cargo#17435)
- docs(trim-paths): workspace remap begins with `.` (rust-lang/cargo#17433)
- docs: Switch from "target triple" to "target tuple" (rust-lang/cargo#17430)
- docs(trim-paths): add limitations and polish (rust-lang/cargo#17425)
- fix(git): Simplify error message (rust-lang/cargo#17429)
- chore(deps): update rust crate base64 to 0.23.0 (rust-lang/cargo#17418)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 5, 2026
Update cargo submodule

9 commits in b2e9d5f9db3fb1c454ab84f10c16508984a266e2..3c0b534756e166d12eb9fd2e1abfe5b42ac6101e
2026-09-02 14:49:16 +0000 to 2026-09-04 17:03:10 +0000
- fix(trim-paths)!: limit options to `none|object|all` (rust-lang/cargo#17432)
- fix(git): Apply pr hint to git-fetch-with-cli (rust-lang/cargo#17437)
- fix(git): Make PR dep note cloer to our style guide (rust-lang/cargo#17436)
- docs: clarify cargo vendor source config option (rust-lang/cargo#17435)
- docs(trim-paths): workspace remap begins with `.` (rust-lang/cargo#17433)
- docs: Switch from "target triple" to "target tuple" (rust-lang/cargo#17430)
- docs(trim-paths): add limitations and polish (rust-lang/cargo#17425)
- fix(git): Simplify error message (rust-lang/cargo#17429)
- chore(deps): update rust crate base64 to 0.23.0 (rust-lang/cargo#17418)
@rustbot rustbot added this to the 1.100.0 milestone Sep 5, 2026
renovate-bot pushed a commit to renovate-bot/rust-lang-_-compiler-builtins that referenced this pull request Sep 7, 2026
Update cargo submodule

9 commits in b2e9d5f9db3fb1c454ab84f10c16508984a266e2..3c0b534756e166d12eb9fd2e1abfe5b42ac6101e
2026-09-02 14:49:16 +0000 to 2026-09-04 17:03:10 +0000
- fix(trim-paths)!: limit options to `none|object|all` (rust-lang/cargo#17432)
- fix(git): Apply pr hint to git-fetch-with-cli (rust-lang/cargo#17437)
- fix(git): Make PR dep note cloer to our style guide (rust-lang/cargo#17436)
- docs: clarify cargo vendor source config option (rust-lang/cargo#17435)
- docs(trim-paths): workspace remap begins with `.` (rust-lang/cargo#17433)
- docs: Switch from "target triple" to "target tuple" (rust-lang/cargo#17430)
- docs(trim-paths): add limitations and polish (rust-lang/cargo#17425)
- fix(git): Simplify error message (rust-lang/cargo#17429)
- chore(deps): update rust crate base64 to 0.23.0 (rust-lang/cargo#17418)
asukaminato0721 pushed a commit to asukaminato0721/rust-analyzer that referenced this pull request Sep 7, 2026
Update cargo submodule

9 commits in b2e9d5f9db3fb1c454ab84f10c16508984a266e2..3c0b534756e166d12eb9fd2e1abfe5b42ac6101e
2026-09-02 14:49:16 +0000 to 2026-09-04 17:03:10 +0000
- fix(trim-paths)!: limit options to `none|object|all` (rust-lang/cargo#17432)
- fix(git): Apply pr hint to git-fetch-with-cli (rust-lang/cargo#17437)
- fix(git): Make PR dep note cloer to our style guide (rust-lang/cargo#17436)
- docs: clarify cargo vendor source config option (rust-lang/cargo#17435)
- docs(trim-paths): workspace remap begins with `.` (rust-lang/cargo#17433)
- docs: Switch from "target triple" to "target tuple" (rust-lang/cargo#17430)
- docs(trim-paths): add limitations and polish (rust-lang/cargo#17425)
- fix(git): Simplify error message (rust-lang/cargo#17429)
- chore(deps): update rust crate base64 to 0.23.0 (rust-lang/cargo#17418)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues Z-trim-paths Nightly: path sanitization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants