about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-06-29 10:28:20 +0530
committerGitHub <noreply@github.com>2022-06-29 10:28:20 +0530
commitc23add778c2aca1fc8b764464fe2a8aa7446f413 (patch)
tree4218ac98281a87fd70a0a96c401f4a0db9113ef3
parentdee9aed07d3e4d54d1d4c56474a9630e4cd3496f (diff)
parent1a5e2d8c92ce1341fcf1632be981f78a3a8d635b (diff)
downloadrust-c23add778c2aca1fc8b764464fe2a8aa7446f413.tar.gz
rust-c23add778c2aca1fc8b764464fe2a8aa7446f413.zip
Rollup merge of #97786 - ferrocene:pa-fix-simulate-remap-prefix, r=Mark-Simulacrum
Account for `-Z simulate-remapped-rust-src-base` when resolving remapped paths

Discovered in #97682, `-Z simulate-remapped-rust-src-base` only partially simulated the behavior of `remap-debuginfo = true`. While the flag successfully simulates the remapping when stdlib's `rmeta` file is loaded, the simulated prefix was not accounted for when the remapped path's local path was being discovered. This caused the flag to not fully simulate the behavior of `remap-debuginfo = true`, leading to inconsistent behaviors.

This PR fixes https://github.com/rust-lang/rust/issues/97682 by also accounting for the simulated path.
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs38
1 files changed, 22 insertions, 16 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index c1ded99a25a..3280fd5c310 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -42,7 +42,7 @@ use std::io;
 use std::iter::TrustedLen;
 use std::mem;
 use std::num::NonZeroUsize;
-use std::path::Path;
+use std::path::PathBuf;
 use tracing::debug;
 
 pub(super) use cstore_impl::provide;
@@ -1473,20 +1473,26 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
         //
         // NOTE: if you update this, you might need to also update bootstrap's code for generating
         // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
-        let virtual_rust_source_base_dir = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR")
-            .map(Path::new)
-            .filter(|_| {
-                // Only spend time on further checks if we have what to translate *to*.
-                sess.opts.real_rust_source_base_dir.is_some()
-                    // Some tests need the translation to be always skipped.
-                    && sess.opts.debugging_opts.translate_remapped_path_to_local_path
-            })
-            .filter(|virtual_dir| {
-                // Don't translate away `/rustc/$hash` if we're still remapping to it,
-                // since that means we're still building `std`/`rustc` that need it,
-                // and we don't want the real path to leak into codegen/debuginfo.
-                !sess.opts.remap_path_prefix.iter().any(|(_from, to)| to == virtual_dir)
-            });
+        let virtual_rust_source_base_dir = [
+            option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from),
+            sess.opts.debugging_opts.simulate_remapped_rust_src_base.clone(),
+        ]
+        .into_iter()
+        .filter(|_| {
+            // Only spend time on further checks if we have what to translate *to*.
+            sess.opts.real_rust_source_base_dir.is_some()
+                // Some tests need the translation to be always skipped.
+                && sess.opts.debugging_opts.translate_remapped_path_to_local_path
+        })
+        .flatten()
+        .filter(|virtual_dir| {
+            // Don't translate away `/rustc/$hash` if we're still remapping to it,
+            // since that means we're still building `std`/`rustc` that need it,
+            // and we don't want the real path to leak into codegen/debuginfo.
+            !sess.opts.remap_path_prefix.iter().any(|(_from, to)| to == virtual_dir)
+        })
+        .collect::<Vec<_>>();
+
         let try_to_translate_virtual_to_real = |name: &mut rustc_span::FileName| {
             debug!(
                 "try_to_translate_virtual_to_real(name={:?}): \
@@ -1494,7 +1500,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
                 name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir,
             );
 
-            if let Some(virtual_dir) = virtual_rust_source_base_dir {
+            for virtual_dir in &virtual_rust_source_base_dir {
                 if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
                     if let rustc_span::FileName::Real(old_name) = name {
                         if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =