@@ -30,7 +30,7 @@ use rustc_span::{BytePos, Pos, SpanData, SpanDecoder, SyntaxContext, DUMMY_SP};
3030
3131use proc_macro:: bridge:: client:: ProcMacro ;
3232use std:: iter:: TrustedLen ;
33- use std:: path:: Path ;
33+ use std:: path:: { Path , PathBuf } ;
3434use std:: { io, iter, mem} ;
3535
3636pub ( super ) use cstore_impl:: provide;
@@ -1589,10 +1589,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15891589 /// Proc macro crates don't currently export spans, so this function does not have
15901590 /// to work for them.
15911591 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 > {
15931597 path. filter ( |_| {
15941598 // 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 ( )
15961600 // Some tests need the translation to be always skipped.
15971601 && sess. opts . unstable_opts . translate_remapped_path_to_local_path
15981602 } )
@@ -1604,25 +1608,34 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16041608 } )
16051609 }
16061610
1611+ let real_rust_source_base_dir = sess. real_rust_source_base_dir ( ) ;
16071612 let try_to_translate_virtual_to_real = |name : & mut rustc_span:: FileName | {
16081613 // Translate the virtual `/rustc/$hash` prefix back to a real directory
16091614 // that should hold actual sources, where possible.
16101615 //
16111616 // NOTE: if you update this, you might need to also update bootstrap's code for generating
16121617 // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
16131618 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+ ) ,
16161629 ] ;
16171630
16181631 debug ! (
16191632 "try_to_translate_virtual_to_real(name={:?}): \
16201633 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,
16221635 ) ;
16231636
16241637 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 {
16261639 if let rustc_span:: FileName :: Real ( old_name) = name {
16271640 if let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
16281641 old_name
@@ -1713,7 +1726,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17131726 // `try_to_translate_virtual_to_real` don't have to worry about how the
17141727 // compiler is bootstrapped.
17151728 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
17171730 && let rustc_span:: FileName :: Real ( ref mut old_name) = name
17181731 {
17191732 let relative_path = match old_name {
0 commit comments