Overhaul filename handling for cross-compiler consistency#149709
Merged
bors merged 13 commits intorust-lang:mainfrom Dec 13, 2025
Merged
Overhaul filename handling for cross-compiler consistency#149709bors merged 13 commits intorust-lang:mainfrom
bors merged 13 commits intorust-lang:mainfrom
Conversation
Collaborator
|
Some changes occurred in coverage instrumentation. cc @Zalathar These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred to the CTFE machinery The Miri subtree was changed cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
268f9ac to
2dc3531
Compare
Collaborator
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
Member
|
@bors try |
This comment has been minimized.
This comment has been minimized.
rust-bors bot
added a commit
that referenced
this pull request
Dec 6, 2025
Overhaul filename handling for cross-compiler consistency
This comment has been minimized.
This comment has been minimized.
bjorn3
reviewed
Dec 6, 2025
This comment has been minimized.
This comment has been minimized.
2dc3531 to
d5be1b8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
d5be1b8 to
21ea4d2
Compare
This comment has been minimized.
This comment has been minimized.
21ea4d2 to
7ab8c59
Compare
This comment has been minimized.
This comment has been minimized.
7ab8c59 to
b91c3d0
Compare
This comment has been minimized.
This comment has been minimized.
b91c3d0 to
b954e1f
Compare
bors
added a commit
that referenced
this pull request
Dec 18, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in #149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
bjorn3
pushed a commit
to bjorn3/rust
that referenced
this pull request
Dec 18, 2025
Overhaul filename handling for cross-compiler consistency This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`). This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang#148328). In order to achieved consistency multiple steps are being taken by this PR: - by making `RealFileName` immutable - by only having `SourceMap::to_real_filename` create `RealFileName` - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed. This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes. Unblocks rust-lang#147611 Fixes rust-lang#148328
bors
added a commit
that referenced
this pull request
Dec 19, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in #149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 19, 2025
… r=davidtwco Improve filenames encoding and misc This PR is a follow-up to rust-lang#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 19, 2025
… r=davidtwco Improve filenames encoding and misc This PR is a follow-up to rust-lang#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 19, 2025
… r=davidtwco Improve filenames encoding and misc This PR is a follow-up to rust-lang#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 19, 2025
… r=davidtwco Improve filenames encoding and misc This PR is a follow-up to rust-lang#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
RalfJung
pushed a commit
to RalfJung/miri
that referenced
this pull request
Dec 20, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Dec 20, 2025
…aumeGomez Handle remapped paths correctly when generating "Source" links Fixes rust-lang#150100. This PR fixes a regression introduced by [rust-lang#149709](rust-lang#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ rust-lang#150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 20, 2025
…aumeGomez Handle remapped paths correctly when generating "Source" links Fixes rust-lang#150100. This PR fixes a regression introduced by [rust-lang#149709](rust-lang#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ rust-lang#150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 20, 2025
…aumeGomez Handle remapped paths correctly when generating "Source" links Fixes rust-lang#150100. This PR fixes a regression introduced by [rust-lang#149709](rust-lang#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ rust-lang#150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
rust-timer
added a commit
that referenced
this pull request
Dec 20, 2025
Rollup merge of #150172 - Urgau:rustdoc-remap-fixes, r=GuillaumeGomez Handle remapped paths correctly when generating "Source" links Fixes #150100. This PR fixes a regression introduced by [#149709](#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ #150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
Shopgra702e
approved these changes
Dec 20, 2025
GuillaumeGomez
pushed a commit
to GuillaumeGomez/rust
that referenced
this pull request
Dec 20, 2025
Overhaul filename handling for cross-compiler consistency This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`). This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang#148328). In order to achieved consistency multiple steps are being taken by this PR: - by making `RealFileName` immutable - by only having `SourceMap::to_real_filename` create `RealFileName` - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed. This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes. Unblocks rust-lang#147611 Fixes rust-lang#148328
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Dec 21, 2025
Improve filenames encoding and misc This PR is a follow-up to rust-lang/rust#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Dec 21, 2025
Handle remapped paths correctly when generating "Source" links Fixes rust-lang/rust#150100. This PR fixes a regression introduced by [#149709](rust-lang/rust#149709), I was overzealous in my changes (https://github.com/rust-lang/rust/pull/149709/changes#diff-e1cf7ef2fb411d24980cd4cbea1e867cc36029e9496e1ceca64cfb6a0e3510f6) and accidentally changed the behavior of `rustdoc` in the presence of remapped, to simply reject them instead of handling them. With this PR remapped paths are handled correctly, in a similar way as it was before. ~~I added a run-make test to make sure we don't regress it again, a simple `rustdoc` test in not sufficient as `rustdoc` is not called on the auxiliary crate. It's not pretty but it works.~~ rust-lang/rust#150172 (comment) rustdoc doesn't have any handling for `--remap-path-scope`, so I used the `MACRO` scope (it was already used [elsewhere](https://github.com/rust-lang/rust/blob/b889870082dd0b0e3594bbfbebb4545d54710829/src/librustdoc/clean/types.rs#L154). cf. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/source.20links.20missing.20for.20nightly.20std.20docs
Kobzol
pushed a commit
to Kobzol/rustc_codegen_gcc
that referenced
this pull request
Dec 21, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
github-actions bot
pushed a commit
to rust-lang/rust-analyzer
that referenced
this pull request
Dec 22, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
Dec 25, 2025
Overhaul filename handling for cross-compiler consistency This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`). This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang#148328). In order to achieved consistency multiple steps are being taken by this PR: - by making `RealFileName` immutable - by only having `SourceMap::to_real_filename` create `RealFileName` - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed. This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes. Unblocks rust-lang#147611 Fixes rust-lang#148328
github-actions bot
pushed a commit
to rust-lang/compiler-builtins
that referenced
this pull request
Dec 28, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
github-actions bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Dec 29, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
Kobzol
pushed a commit
to Kobzol/rustc_codegen_cranelift
that referenced
this pull request
Dec 29, 2025
Prefer remapping the relative `library/` and `compiler/` directories This is done to avoid leaking the relative paths to the standard library after the overall of filenames in rust-lang/rust#149709. Noted that the paths were already leaking before, but to a lesser extent since most (but not all) the paths embedded in the distributed `rlib` were absolute. In general Cargo compiles workspace members with relative paths, so it's better anyway to remap the relative path. In addition to our tests I have manually confirmed that it also works as expected for the printed diagnostics paths. cf. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/remapping.20of.20the.20standard.20library/near/564093571
Kobzol
pushed a commit
to Kobzol/rustc_codegen_cranelift
that referenced
this pull request
Dec 29, 2025
Improve filenames encoding and misc This PR is a follow-up to rust-lang/rust#149709, it aims at preventing a double encoding when there are no remapping, as well as making some small improvements to the code. Best reviewed commit by commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR overhauls the way we handle filenames in the compiler and
rmetain order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming fromrmeta).This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see #148328).
In order to achieved consistency multiple steps are being taken by this PR:
RealFileNameimmutableSourceMap::to_real_filenamecreateRealFileNameRealFileNamecan be created from anyPathand are remapped afterwards, which creates consistency issueRealFileNameholds it's working directory, embeddable name and the remapped scopesSession, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filenameIn order for
SourceMap::to_real_filenameto know which scopes to applyFilePathMappingnow takes the current remapping scopes to apply, which makesFileNameDisplayPreferenceand company useless and are removed.This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.
Unblocks #147611
Fixes #148328
cc @RalfJung @oli-obk
r? @davidtwco