Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd4dfd7

Browse files
authoredMar 17, 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
2 parents c19ce9d + b148106 commit cd4dfd7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎src/librustdoc/clean/render_macro_matchers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_ast_pretty::pprust::PrintState;
44
use rustc_ast_pretty::pprust::state::State as Printer;
55
use rustc_middle::ty::TyCtxt;
66
use rustc_session::parse::ParseSess;
7-
use rustc_span::Span;
87
use rustc_span::symbol::{Ident, Symbol, kw};
8+
use rustc_span::{FileName, Span};
99

1010
/// Render a macro matcher in a format suitable for displaying to the user
1111
/// as part of an item declaration.
@@ -63,7 +63,7 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String
6363

6464
// Create a Parser.
6565
let psess = ParseSess::new(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec());
66-
let file_name = source_map.span_to_filename(span);
66+
let file_name = FileName::macro_expansion_source_code(&snippet);
6767
let mut parser =
6868
match rustc_parse::new_parser_from_source_str(&psess, file_name, snippet.clone()) {
6969
Ok(parser) => parser,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Regression test for "attempted to remap an already remapped filename" ICE in rustdoc
2+
// when using --remap-path-prefix with macro rendering.
3+
// <https://github.com/rust-lang/rust/issues/138520>
4+
5+
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path
6+
//@ rustc-env:RUST_BACKTRACE=0
7+
//@ build-pass
8+
9+
macro_rules! f(() => {});

0 commit comments

Comments
 (0)
Failed to load comments.