Skip to content

Fix ICE: attempted to remap an already remapped filename#138556

Merged
bors merged 1 commit intorust-lang:masterfrom
charmitro:already-remapped-filename
Mar 18, 2025
Merged

Fix ICE: attempted to remap an already remapped filename#138556
bors merged 1 commit intorust-lang:masterfrom
charmitro:already-remapped-filename

Conversation

@charmitro
Copy link
Copy Markdown
Contributor

@charmitro charmitro commented Mar 16, 2025

This commit fixes an internal compiler error (ICE) that occurs when
rustdoc attempts to process macros with a remapped filename. The issue
arose during macro expansion when the --remap-path-prefix option was
used.

Instead of passing remapped filenames through, which would trigger the
"attempted to remap an already remapped filename" panic, we now
extract the original local path from remapped filenames before
processing them.

A test case has been added to verify this behavior.

Fixes #138520

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 16, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
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

@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 16, 2025
@charmitro charmitro force-pushed the already-remapped-filename branch 2 times, most recently from e5e767e to 1d96771 Compare March 16, 2025 14:19
@nnethercote nnethercote assigned Urgau and unassigned nnethercote Mar 16, 2025
@nnethercote
Copy link
Copy Markdown
Contributor

Reassigning the review to @Urgau, who has stronger opinions and more expertise here than I do.

This commit fixes an internal compiler error (ICE) that occurs when
rustdoc attempts to process macros with a remapped filename. The issue
arose during macro expansion when the `--remap-path-prefix` option was
used.

Instead of passing remapped filenames through, which would trigger the
"attempted to remap an already remapped filename" panic, we now
extract the original local path from remapped filenames before
processing them.

A test case has been added to verify this behavior.

Fixes rust-lang#138520

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
@charmitro charmitro force-pushed the already-remapped-filename branch from 1d96771 to b148106 Compare March 16, 2025 22:37
@GuillaumeGomez
Copy link
Copy Markdown
Member

Looks good to me, thanks for working on this! I'll let @Urgau have the final word.

@Urgau
Copy link
Copy Markdown
Member

Urgau commented Mar 17, 2025

@bors r=GuillaumeGomez,Urgau rollup

@bors
Copy link
Copy Markdown
Collaborator

bors commented Mar 17, 2025

📌 Commit b148106 has been approved by GuillaumeGomez,Urgau

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 17, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#138384 (Move `hir::Item::ident` into `hir::ItemKind`.)
 - rust-lang#138508 (Clarify "owned data" in E0515.md)
 - rust-lang#138531 (Store test diffs in job summaries and improve analysis formatting)
 - rust-lang#138533 (Only use `DIST_TRY_BUILD` for try jobs that were not selected explicitly)
 - rust-lang#138556 (Fix ICE: attempted to remap an already remapped filename)
 - rust-lang#138608 (rustc_target: Add target feature constraints for LoongArch)
 - rust-lang#138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 18, 2025
…e, r=GuillaumeGomez,Urgau

Fix ICE: attempted to remap an already remapped filename

This commit fixes an internal compiler error (ICE) that occurs when
rustdoc attempts to process macros with a remapped filename. The issue
arose during macro expansion when the `--remap-path-prefix` option was
used.

Instead of passing remapped filenames through, which would trigger the
"attempted to remap an already remapped filename" panic, we now
extract the original local path from remapped filenames before
processing them.

A test case has been added to verify this behavior.

Fixes rust-lang#138520
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 18, 2025
…e, r=GuillaumeGomez,Urgau

Fix ICE: attempted to remap an already remapped filename

This commit fixes an internal compiler error (ICE) that occurs when
rustdoc attempts to process macros with a remapped filename. The issue
arose during macro expansion when the `--remap-path-prefix` option was
used.

Instead of passing remapped filenames through, which would trigger the
"attempted to remap an already remapped filename" panic, we now
extract the original local path from remapped filenames before
processing them.

A test case has been added to verify this behavior.

Fixes rust-lang#138520
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#136320 (exit: document interaction with C)
 - rust-lang#138301 (Implement `read_buf` for Hermit)
 - rust-lang#138508 (Clarify "owned data" in E0515.md)
 - rust-lang#138556 (Fix ICE: attempted to remap an already remapped filename)
 - rust-lang#138569 (rustdoc-json: Add tests for `#[repr(...)]`)
 - rust-lang#138608 (rustc_target: Add target feature constraints for LoongArch)
 - rust-lang#138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#138384 (Move `hir::Item::ident` into `hir::ItemKind`.)
 - rust-lang#138508 (Clarify "owned data" in E0515.md)
 - rust-lang#138531 (Store test diffs in job summaries and improve analysis formatting)
 - rust-lang#138533 (Only use `DIST_TRY_BUILD` for try jobs that were not selected explicitly)
 - rust-lang#138556 (Fix ICE: attempted to remap an already remapped filename)
 - rust-lang#138608 (rustc_target: Add target feature constraints for LoongArch)
 - rust-lang#138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cd4dfd7 into rust-lang:master Mar 18, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 18, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2025
Rollup merge of rust-lang#138556 - charmitro:already-remapped-filename, r=GuillaumeGomez,Urgau

Fix ICE: attempted to remap an already remapped filename

This commit fixes an internal compiler error (ICE) that occurs when
rustdoc attempts to process macros with a remapped filename. The issue
arose during macro expansion when the `--remap-path-prefix` option was
used.

Instead of passing remapped filenames through, which would trigger the
"attempted to remap an already remapped filename" panic, we now
extract the original local path from remapped filenames before
processing them.

A test case has been added to verify this behavior.

Fixes rust-lang#138520
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 20, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#138384 (Move `hir::Item::ident` into `hir::ItemKind`.)
 - rust-lang#138508 (Clarify "owned data" in E0515.md)
 - rust-lang#138531 (Store test diffs in job summaries and improve analysis formatting)
 - rust-lang#138533 (Only use `DIST_TRY_BUILD` for try jobs that were not selected explicitly)
 - rust-lang#138556 (Fix ICE: attempted to remap an already remapped filename)
 - rust-lang#138608 (rustc_target: Add target feature constraints for LoongArch)
 - rust-lang#138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
ojeda added a commit to ojeda/linux that referenced this pull request Mar 31, 2026
With the minimum version bump in place, `rustdoc` now always recognizes
the `--remap-path-prefix` flag.

In addition, the Internal Compiler Error that the comment mentions [1]
was fixed in Rust 1.87.0 [2], so we still need to skip the flag for
the normal `rustdoc` case, but not for `--test` since the ICE does not
reproduce there -- please see commit 2c8725c ("rust: kbuild: skip
`--remap-path-prefix` for `rustdoc`").

Thus update the comment and remove the skipping of the flag for the
`--test` case.

Note that commit dda1350 ("rust: build: remap path to avoid
absolute path") re-landed the `--remap-path-prefix` flag (together with
`--remap-path-scope`), so we keep the workaround, i.e. an alternative
could have been to simply delete the skip entirely, but since we still
have it and it will be needed when this gets merged, let's keep it.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this pull request Mar 31, 2026
The Internal Compiler Error that the comment mentions [1] was fixed in
Rust 1.87.0 [2]. And, for other workarounds, we plan on limiting where
we apply them [3].

Thus limit the ICE one too.

This will help to make sure the workaround is not needed anymore on
newer versions.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Link: https://lore.kernel.org/rust-for-linux/20260205131815.2943152-2-mlksvender@gmail.com/ [3]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this pull request Mar 31, 2026
With the minimum version bump in place, `rustdoc` now always recognizes
the `--remap-path-prefix` flag.

In addition, the Internal Compiler Error that the comment mentions [1]
was fixed in Rust 1.87.0 [2], so we still need to skip the flag for
the normal `rustdoc` case, but not for `--test` since the ICE does not
reproduce there -- please see commit 2c8725c ("rust: kbuild: skip
`--remap-path-prefix` for `rustdoc`").

Thus update the comment and remove the skipping of the flag for the
`--test` case.

Note that commit dda1350 ("rust: build: remap path to avoid
absolute path") re-landed the `--remap-path-prefix` flag (together with
`--remap-path-scope`), so we keep the workaround, i.e. an alternative
could have been to simply delete the skip entirely, but since we still
have it and it will be needed when this gets merged, let's keep it.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this pull request Mar 31, 2026
The Internal Compiler Error that the comment mentions [1] was fixed in
Rust 1.87.0 [2]. And, for other workarounds, we plan on limiting where
we apply them [3].

Thus limit the ICE one too.

This will help to make sure the workaround is not needed anymore on
newer versions.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Link: https://lore.kernel.org/rust-for-linux/20260205131815.2943152-2-mlksvender@gmail.com/ [3]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this pull request Apr 1, 2026
With the minimum version bump in place, `rustdoc` now always recognizes
the `--remap-path-prefix` flag.

In addition, the Internal Compiler Error that the comment mentions [1]
was fixed in Rust 1.87.0 [2], so we still need to skip the flag for
the normal `rustdoc` case, but not for `--test` since the ICE does not
reproduce there -- please see commit 2c8725c ("rust: kbuild: skip
`--remap-path-prefix` for `rustdoc`").

Thus update the comment and remove the skipping of the flag for the
`--test` case.

Note that commit dda1350 ("rust: build: remap path to avoid
absolute path") re-landed the `--remap-path-prefix` flag (together with
`--remap-path-scope`), so we keep the workaround, i.e. an alternative
could have been to simply delete the skip entirely, but since we still
have it and it will be needed when this gets merged, let's keep it.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this pull request Apr 1, 2026
The Internal Compiler Error that the comment mentions [1] was fixed in
Rust 1.87.0 [2]. And, for other workarounds, we plan on limiting where
we apply them [3].

Thus limit the ICE one too.

This will help to make sure the workaround is not needed anymore on
newer versions.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Link: https://lore.kernel.org/rust-for-linux/20260205131815.2943152-2-mlksvender@gmail.com/ [3]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Darksonn pushed a commit to Darksonn/linux that referenced this pull request Apr 1, 2026
With the minimum version bump in place, `rustdoc` now always recognizes
the `--remap-path-prefix` flag.

In addition, the Internal Compiler Error that the comment mentions [1]
was fixed in Rust 1.87.0 [2], so we still need to skip the flag for
the normal `rustdoc` case, but not for `--test` since the ICE does not
reproduce there -- please see commit 2c8725c ("rust: kbuild: skip
`--remap-path-prefix` for `rustdoc`").

Thus update the comment and remove the skipping of the flag for the
`--test` case.

Note that commit dda1350 ("rust: build: remap path to avoid
absolute path") re-landed the `--remap-path-prefix` flag (together with
`--remap-path-scope`), so we keep the workaround, i.e. an alternative
could have been to simply delete the skip entirely, but since we still
have it and it will be needed when this gets merged, let's keep it.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20260401114540.30108-9-ojeda@kernel.org
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Darksonn pushed a commit to Darksonn/linux that referenced this pull request Apr 1, 2026
The Internal Compiler Error that the comment mentions [1] was fixed in
Rust 1.87.0 [2]. And, for other workarounds, we plan on limiting where
we apply them [3].

Thus limit the ICE one too.

This will help to make sure the workaround is not needed anymore on
newer versions.

Link: rust-lang/rust#138520 [1]
Link: rust-lang/rust#138556 [2]
Link: https://lore.kernel.org/rust-for-linux/20260205131815.2943152-2-mlksvender@gmail.com/ [3]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20260401114540.30108-10-ojeda@kernel.org
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
ojeda added a commit to Rust-for-Linux/linux that referenced this pull request Apr 6, 2026
Commit 8cf5b3f ("Revert "kbuild, rust: use -fremap-path-prefix
to make paths relative"") removed `--remap-path-prefix` from the build
system, so the workarounds are not needed anymore.

Thus remove them.

Note that the flag has landed again in parallel in this cycle in
commit dda1350 ("rust: build: remap path to avoid absolute path"),
together with `--remap-path-scope=macro` [1]. However, they are gated on
`rustc-option-yn, --remap-path-scope=macro`, which means they are both
only passed starting with Rust 1.95.0 [2]:

  `--remap-path-scope` is only stable in Rust 1.95, so use `rustc-option`
  to detect its presence. This feature has been available as
  `-Zremap-path-scope` for all versions that we support; however due to
  bugs in the Rust compiler, it does not work reliably until 1.94. I opted
  to not enable it for 1.94 as it's just a single version that we missed.

In turn, that means the workarounds removed here should not be needed
again (even with the flag added again above), since:

  - `rustdoc` now recognizes the `--remap-path-prefix` flag since Rust
    1.81.0 [3] (even if it is still an unstable feature [4]).

  - The Internal Compiler Error [5] that the comment mentions was fixed in
    Rust 1.87.0 [6]. We tested that was the case in a previous version
    of this series by making the workaround conditional [7][8].

...which are both older versions than Rust 1.95.0.

We will still need to skip `--remap-path-scope` for `rustdoc` though,
since `rustdoc` does not support that one yet [4].

Link: rust-lang/rust#111540 [1]
Link: rust-lang/rust#147611 [2]
Link: rust-lang/rust#107099 [3]
Link: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--remap-path-prefix-remap-source-code-paths-in-output [4]
Link: rust-lang/rust#138520 [5]
Link: rust-lang/rust#138556 [6]
Link: https://lore.kernel.org/rust-for-linux/20260401114540.30108-9-ojeda@kernel.org/ [7]
Link: https://lore.kernel.org/rust-for-linux/20260401114540.30108-10-ojeda@kernel.org/ [8]
Acked-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260405235309.418950-2-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to Rust-for-Linux/linux that referenced this pull request Apr 7, 2026
Commit 8cf5b3f ("Revert "kbuild, rust: use -fremap-path-prefix
to make paths relative"") removed `--remap-path-prefix` from the build
system, so the workarounds are not needed anymore.

Thus remove them.

Note that the flag has landed again in parallel in this cycle in
commit dda1350 ("rust: build: remap path to avoid absolute path"),
together with `--remap-path-scope=macro` [1]. However, they are gated on
`rustc-option-yn, --remap-path-scope=macro`, which means they are both
only passed starting with Rust 1.95.0 [2]:

  `--remap-path-scope` is only stable in Rust 1.95, so use `rustc-option`
  to detect its presence. This feature has been available as
  `-Zremap-path-scope` for all versions that we support; however due to
  bugs in the Rust compiler, it does not work reliably until 1.94. I opted
  to not enable it for 1.94 as it's just a single version that we missed.

In turn, that means the workarounds removed here should not be needed
again (even with the flag added again above), since:

  - `rustdoc` now recognizes the `--remap-path-prefix` flag since Rust
    1.81.0 [3] (even if it is still an unstable feature [4]).

  - The Internal Compiler Error [5] that the comment mentions was fixed in
    Rust 1.87.0 [6]. We tested that was the case in a previous version
    of this series by making the workaround conditional [7][8].

...which are both older versions than Rust 1.95.0.

We will still need to skip `--remap-path-scope` for `rustdoc` though,
since `rustdoc` does not support that one yet [4].

Link: rust-lang/rust#111540 [1]
Link: rust-lang/rust#147611 [2]
Link: rust-lang/rust#107099 [3]
Link: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--remap-path-prefix-remap-source-code-paths-in-output [4]
Link: rust-lang/rust#138520 [5]
Link: rust-lang/rust#138556 [6]
Link: https://lore.kernel.org/rust-for-linux/20260401114540.30108-9-ojeda@kernel.org/ [7]
Link: https://lore.kernel.org/rust-for-linux/20260401114540.30108-10-ojeda@kernel.org/ [8]
Link: https://patch.msgid.link/20260405235309.418950-2-ojeda@kernel.org
Acked-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

ICE: rustdoc: attempted to remap an already remapped filename

6 participants