Skip to content

Commit c23add7

Browse files
authored
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 #97682 by also accounting for the simulated path.
2 parents dee9aed + 1a5e2d8 commit c23add7

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::io;
4242
use std::iter::TrustedLen;
4343
use std::mem;
4444
use std::num::NonZeroUsize;
45-
use std::path::Path;
45+
use std::path::PathBuf;
4646
use tracing::debug;
4747

4848
pub(super) use cstore_impl::provide;
@@ -1473,28 +1473,34 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14731473
//
14741474
// NOTE: if you update this, you might need to also update bootstrap's code for generating
14751475
// the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
1476-
let virtual_rust_source_base_dir = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR")
1477-
.map(Path::new)
1478-
.filter(|_| {
1479-
// Only spend time on further checks if we have what to translate *to*.
1480-
sess.opts.real_rust_source_base_dir.is_some()
1481-
// Some tests need the translation to be always skipped.
1482-
&& sess.opts.debugging_opts.translate_remapped_path_to_local_path
1483-
})
1484-
.filter(|virtual_dir| {
1485-
// Don't translate away `/rustc/$hash` if we're still remapping to it,
1486-
// since that means we're still building `std`/`rustc` that need it,
1487-
// and we don't want the real path to leak into codegen/debuginfo.
1488-
!sess.opts.remap_path_prefix.iter().any(|(_from, to)| to == virtual_dir)
1489-
});
1476+
let virtual_rust_source_base_dir = [
1477+
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from),
1478+
sess.opts.debugging_opts.simulate_remapped_rust_src_base.clone(),
1479+
]
1480+
.into_iter()
1481+
.filter(|_| {
1482+
// Only spend time on further checks if we have what to translate *to*.
1483+
sess.opts.real_rust_source_base_dir.is_some()
1484+
// Some tests need the translation to be always skipped.
1485+
&& sess.opts.debugging_opts.translate_remapped_path_to_local_path
1486+
})
1487+
.flatten()
1488+
.filter(|virtual_dir| {
1489+
// Don't translate away `/rustc/$hash` if we're still remapping to it,
1490+
// since that means we're still building `std`/`rustc` that need it,
1491+
// and we don't want the real path to leak into codegen/debuginfo.
1492+
!sess.opts.remap_path_prefix.iter().any(|(_from, to)| to == virtual_dir)
1493+
})
1494+
.collect::<Vec<_>>();
1495+
14901496
let try_to_translate_virtual_to_real = |name: &mut rustc_span::FileName| {
14911497
debug!(
14921498
"try_to_translate_virtual_to_real(name={:?}): \
14931499
virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
14941500
name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir,
14951501
);
14961502

1497-
if let Some(virtual_dir) = virtual_rust_source_base_dir {
1503+
for virtual_dir in &virtual_rust_source_base_dir {
14981504
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
14991505
if let rustc_span::FileName::Real(old_name) = name {
15001506
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =

0 commit comments

Comments
 (0)