@@ -41,7 +41,7 @@ use std::io;
41
41
use std:: iter:: TrustedLen ;
42
42
use std:: mem;
43
43
use std:: num:: NonZeroUsize ;
44
- use std:: path:: PathBuf ;
44
+ use std:: path:: Path ;
45
45
use tracing:: debug;
46
46
47
47
pub ( super ) use cstore_impl:: provide;
@@ -1474,30 +1474,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1474
1474
/// Proc macro crates don't currently export spans, so this function does not have
1475
1475
/// to work for them.
1476
1476
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
+
1477
1492
// Translate the virtual `/rustc/$hash` prefix back to a real directory
1478
1493
// that should hold actual sources, where possible.
1479
1494
//
1480
1495
// NOTE: if you update this, you might need to also update bootstrap's code for generating
1481
1496
// the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
1482
1497
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
+ ] ;
1501
1501
1502
1502
let try_to_translate_virtual_to_real = |name : & mut rustc_span:: FileName | {
1503
1503
debug ! (
@@ -1506,7 +1506,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1506
1506
name, virtual_rust_source_base_dir, sess. opts. real_rust_source_base_dir,
1507
1507
) ;
1508
1508
1509
- for virtual_dir in & virtual_rust_source_base_dir {
1509
+ for virtual_dir in virtual_rust_source_base_dir. iter ( ) . flatten ( ) {
1510
1510
if let Some ( real_dir) = & sess. opts . real_rust_source_base_dir {
1511
1511
if let rustc_span:: FileName :: Real ( old_name) = name {
1512
1512
if let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
0 commit comments