@@ -41,7 +41,7 @@ use std::io;
4141use std:: iter:: TrustedLen ;
4242use std:: mem;
4343use std:: num:: NonZeroUsize ;
44- use std:: path:: PathBuf ;
44+ use std:: path:: Path ;
4545use tracing:: debug;
4646
4747pub ( super ) use cstore_impl:: provide;
@@ -1474,30 +1474,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14741474 /// Proc macro crates don't currently export spans, so this function does not have
14751475 /// to work for them.
14761476 fn imported_source_files ( self , sess : & Session ) -> & ' a [ ImportedSourceFile ] {
1477+ fn filter < ' a > ( sess : & Session , path : Option < & ' a Path > ) -> Option < & ' a Path > {
1478+ path. 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 . unstable_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+ } )
1490+ }
1491+
14771492 // Translate the virtual `/rustc/$hash` prefix back to a real directory
14781493 // that should hold actual sources, where possible.
14791494 //
14801495 // NOTE: if you update this, you might need to also update bootstrap's code for generating
14811496 // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
14821497 let virtual_rust_source_base_dir = [
1483- option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) . map ( PathBuf :: from) ,
1484- sess. opts . unstable_opts . simulate_remapped_rust_src_base . clone ( ) ,
1485- ]
1486- . into_iter ( )
1487- . filter ( |_| {
1488- // Only spend time on further checks if we have what to translate *to*.
1489- sess. opts . real_rust_source_base_dir . is_some ( )
1490- // Some tests need the translation to be always skipped.
1491- && sess. opts . unstable_opts . translate_remapped_path_to_local_path
1492- } )
1493- . flatten ( )
1494- . filter ( |virtual_dir| {
1495- // Don't translate away `/rustc/$hash` if we're still remapping to it,
1496- // since that means we're still building `std`/`rustc` that need it,
1497- // and we don't want the real path to leak into codegen/debuginfo.
1498- !sess. opts . remap_path_prefix . iter ( ) . any ( |( _from, to) | to == virtual_dir)
1499- } )
1500- . collect :: < Vec < _ > > ( ) ;
1498+ filter ( sess, option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) . map ( Path :: new) ) ,
1499+ filter ( sess, sess. opts . unstable_opts . simulate_remapped_rust_src_base . as_deref ( ) ) ,
1500+ ] ;
15011501
15021502 let try_to_translate_virtual_to_real = |name : & mut rustc_span:: FileName | {
15031503 debug ! (
@@ -1506,7 +1506,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15061506 name, virtual_rust_source_base_dir, sess. opts. real_rust_source_base_dir,
15071507 ) ;
15081508
1509- for virtual_dir in & virtual_rust_source_base_dir {
1509+ for virtual_dir in virtual_rust_source_base_dir. iter ( ) . flatten ( ) {
15101510 if let Some ( real_dir) = & sess. opts . real_rust_source_base_dir {
15111511 if let rustc_span:: FileName :: Real ( old_name) = name {
15121512 if let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
0 commit comments