about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-03-17 22:49:07 +0100
committerGitHub <noreply@github.com>2025-03-17 22:49:07 +0100
commitcd4dfd77fa7ac0689a595f479c61a9dc6bc8ce8c (patch)
tree96a75339a7f2ee9d944d6fb99ac78e3010375dcd /src
parentc19ce9df8d9e270b0082d07c0d22550629fc5878 (diff)
parentb14810669a805003cf6392447c08eed79441936f (diff)
downloadrust-cd4dfd77fa7ac0689a595f479c61a9dc6bc8ce8c.tar.gz
rust-cd4dfd77fa7ac0689a595f479c61a9dc6bc8ce8c.zip
Rollup merge of #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 #138520
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/render_macro_matchers.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs
index 88db853d7c3..31f9c284d7d 100644
--- a/src/librustdoc/clean/render_macro_matchers.rs
+++ b/src/librustdoc/clean/render_macro_matchers.rs
@@ -4,8 +4,8 @@ use rustc_ast_pretty::pprust::PrintState;
 use rustc_ast_pretty::pprust::state::State as Printer;
 use rustc_middle::ty::TyCtxt;
 use rustc_session::parse::ParseSess;
-use rustc_span::Span;
 use rustc_span::symbol::{Ident, Symbol, kw};
+use rustc_span::{FileName, Span};
 
 /// Render a macro matcher in a format suitable for displaying to the user
 /// as part of an item declaration.
@@ -63,7 +63,7 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String
 
     // Create a Parser.
     let psess = ParseSess::new(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec());
-    let file_name = source_map.span_to_filename(span);
+    let file_name = FileName::macro_expansion_source_code(&snippet);
     let mut parser =
         match rustc_parse::new_parser_from_source_str(&psess, file_name, snippet.clone()) {
             Ok(parser) => parser,