@@ -30,7 +30,7 @@ use rustc_span::{BytePos, Pos, SpanData, SpanDecoder, SyntaxContext, DUMMY_SP};
30
30
31
31
use proc_macro:: bridge:: client:: ProcMacro ;
32
32
use std:: iter:: TrustedLen ;
33
- use std:: path:: Path ;
33
+ use std:: path:: { Path , PathBuf } ;
34
34
use std:: { io, iter, mem} ;
35
35
36
36
pub ( super ) use cstore_impl:: provide;
@@ -1589,10 +1589,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1589
1589
/// Proc macro crates don't currently export spans, so this function does not have
1590
1590
/// to work for them.
1591
1591
fn imported_source_file ( self , source_file_index : u32 , sess : & Session ) -> ImportedSourceFile {
1592
- fn filter < ' a > ( sess : & Session , path : Option < & ' a Path > ) -> Option < & ' a Path > {
1592
+ fn filter < ' a > (
1593
+ sess : & Session ,
1594
+ real_rust_source_base_dir : & Option < PathBuf > ,
1595
+ path : Option < & ' a Path > ,
1596
+ ) -> Option < & ' a Path > {
1593
1597
path. filter ( |_| {
1594
1598
// Only spend time on further checks if we have what to translate *to*.
1595
- sess . opts . real_rust_source_base_dir . is_some ( )
1599
+ real_rust_source_base_dir. is_some ( )
1596
1600
// Some tests need the translation to be always skipped.
1597
1601
&& sess. opts . unstable_opts . translate_remapped_path_to_local_path
1598
1602
} )
@@ -1604,25 +1608,34 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1604
1608
} )
1605
1609
}
1606
1610
1611
+ let real_rust_source_base_dir = sess. real_rust_source_base_dir ( ) ;
1607
1612
let try_to_translate_virtual_to_real = |name : & mut rustc_span:: FileName | {
1608
1613
// Translate the virtual `/rustc/$hash` prefix back to a real directory
1609
1614
// that should hold actual sources, where possible.
1610
1615
//
1611
1616
// NOTE: if you update this, you might need to also update bootstrap's code for generating
1612
1617
// the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
1613
1618
let virtual_rust_source_base_dir = [
1614
- filter ( sess, option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) . map ( Path :: new) ) ,
1615
- filter ( sess, sess. opts . unstable_opts . simulate_remapped_rust_src_base . as_deref ( ) ) ,
1619
+ filter (
1620
+ sess,
1621
+ & real_rust_source_base_dir,
1622
+ option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) . map ( Path :: new) ,
1623
+ ) ,
1624
+ filter (
1625
+ sess,
1626
+ & real_rust_source_base_dir,
1627
+ sess. opts . unstable_opts . simulate_remapped_rust_src_base . as_deref ( ) ,
1628
+ ) ,
1616
1629
] ;
1617
1630
1618
1631
debug ! (
1619
1632
"try_to_translate_virtual_to_real(name={:?}): \
1620
1633
virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
1621
- name, virtual_rust_source_base_dir, sess . opts . real_rust_source_base_dir,
1634
+ name, virtual_rust_source_base_dir, real_rust_source_base_dir,
1622
1635
) ;
1623
1636
1624
1637
for virtual_dir in virtual_rust_source_base_dir. iter ( ) . flatten ( ) {
1625
- if let Some ( real_dir) = & sess . opts . real_rust_source_base_dir {
1638
+ if let Some ( real_dir) = & real_rust_source_base_dir {
1626
1639
if let rustc_span:: FileName :: Real ( old_name) = name {
1627
1640
if let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
1628
1641
old_name
@@ -1713,7 +1726,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1713
1726
// `try_to_translate_virtual_to_real` don't have to worry about how the
1714
1727
// compiler is bootstrapped.
1715
1728
if let Some ( virtual_dir) = & sess. opts . unstable_opts . simulate_remapped_rust_src_base
1716
- && let Some ( real_dir) = & sess . opts . real_rust_source_base_dir
1729
+ && let Some ( real_dir) = & real_rust_source_base_dir
1717
1730
&& let rustc_span:: FileName :: Real ( ref mut old_name) = name
1718
1731
{
1719
1732
let relative_path = match old_name {
0 commit comments