@@ -1606,91 +1606,92 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16061606 /// Proc macro crates don't currently export spans, so this function does not have
16071607 /// to work for them.
16081608 fn imported_source_files ( & self , sess : & Session ) -> & ' a [ ImportedSourceFile ] {
1609- // Translate the virtual `/rustc/$hash` prefix back to a real directory
1610- // that should hold actual sources, where possible.
1611- //
1612- // NOTE: if you update this, you might need to also update bootstrap's code for generating
1613- // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
1614- let virtual_rust_source_base_dir = sess
1615- . opts
1616- . debugging_opts
1617- . force_virtual_source_base
1618- . as_deref ( )
1619- . or ( option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) )
1620- . map ( Path :: new)
1621- . filter ( |_| {
1622- // Only spend time on further checks if we have what to translate *to*.
1623- sess. real_rust_source_base_dir . is_some ( )
1624- } )
1625- . filter ( |virtual_dir| {
1626- // Don't translate away `/rustc/$hash` if we're still remapping to it,
1627- // since that means we're still building `std`/`rustc` that need it,
1628- // and we don't want the real path to leak into codegen/debuginfo.
1629- !sess. opts . remap_path_prefix . iter ( ) . any ( |( _from, to) | to == virtual_dir)
1630- } ) ;
1631- let try_to_translate_virtual_to_real =
1632- |name : & mut rustc_span:: FileName , name_hash : & mut u128 | {
1633- debug ! (
1634- "try_to_translate_virtual_to_real(name={:?}): \
1635- virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
1636- name, virtual_rust_source_base_dir, sess. real_rust_source_base_dir,
1637- ) ;
1609+ self . cdata . source_map_import_info . get_or_init ( || {
1610+ // Translate the virtual `/rustc/$hash` prefix back to a real directory
1611+ // that should hold actual sources, where possible.
1612+ //
1613+ // NOTE: if you update this, you might need to also update bootstrap's code for generating
1614+ // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
1615+ let virtual_rust_source_base_dir = sess
1616+ . opts
1617+ . debugging_opts
1618+ . force_virtual_source_base
1619+ . as_deref ( )
1620+ . or ( option_env ! ( "CFG_VIRTUAL_RUST_SOURCE_BASE_DIR" ) )
1621+ . map ( Path :: new)
1622+ . filter ( |_| {
1623+ // Only spend time on further checks if we have what to translate *to*.
1624+ sess. real_rust_source_base_dir . is_some ( )
1625+ } )
1626+ . filter ( |virtual_dir| {
1627+ // Don't translate away `/rustc/$hash` if we're still remapping to it,
1628+ // since that means we're still building `std`/`rustc` that need it,
1629+ // and we don't want the real path to leak into codegen/debuginfo.
1630+ !sess. opts . remap_path_prefix . iter ( ) . any ( |( _from, to) | to == virtual_dir)
1631+ } ) ;
1632+ let try_to_translate_virtual_to_real =
1633+ |name : & mut rustc_span:: FileName , name_hash : & mut u128 | {
1634+ debug ! (
1635+ "try_to_translate_virtual_to_real(name={:?}): \
1636+ virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
1637+ name, virtual_rust_source_base_dir, sess. real_rust_source_base_dir,
1638+ ) ;
16381639
1639- if let Some ( virtual_dir) = virtual_rust_source_base_dir {
1640- if let Some ( real_dir) = & sess. real_rust_source_base_dir {
1641- if let rustc_span:: FileName :: Real ( old_name) = name {
1642- if let rustc_span:: RealFileName :: Named ( one_path) = old_name {
1643- if let Ok ( rest) = one_path. strip_prefix ( virtual_dir) {
1644- let virtual_name = one_path. clone ( ) ;
1645-
1646- // The std library crates are in
1647- // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1648- // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1649- // detect crates from the std libs and handle them specially.
1650- const STD_LIBS : & [ & str ] = & [
1651- "core" ,
1652- "alloc" ,
1653- "std" ,
1654- "test" ,
1655- "term" ,
1656- "unwind" ,
1657- "proc_macro" ,
1658- "panic_abort" ,
1659- "panic_unwind" ,
1660- "profiler_builtins" ,
1661- "rtstartup" ,
1662- "rustc-std-workspace-core" ,
1663- "rustc-std-workspace-alloc" ,
1664- "rustc-std-workspace-std" ,
1665- "backtrace" ,
1666- ] ;
1667- let is_std_lib = STD_LIBS . iter ( ) . any ( |l| rest. starts_with ( l) ) ;
1668-
1669- let new_path = if is_std_lib {
1670- real_dir. join ( "library" ) . join ( rest)
1671- } else {
1672- real_dir. join ( rest)
1673- } ;
1674-
1675- debug ! (
1676- "try_to_translate_virtual_to_real: `{}` -> `{}`" ,
1677- virtual_name. display( ) ,
1678- new_path. display( ) ,
1679- ) ;
1680- let new_name = rustc_span:: RealFileName :: Devirtualized {
1681- local_path : new_path,
1682- virtual_name,
1683- } ;
1684- * old_name = new_name;
1685- * name_hash = name. name_hash ( ) ;
1640+ if let Some ( virtual_dir) = virtual_rust_source_base_dir {
1641+ if let Some ( real_dir) = & sess. real_rust_source_base_dir {
1642+ if let rustc_span:: FileName :: Real ( old_name) = name {
1643+ if let rustc_span:: RealFileName :: Named ( one_path) = old_name {
1644+ if let Ok ( rest) = one_path. strip_prefix ( virtual_dir) {
1645+ let virtual_name = one_path. clone ( ) ;
1646+
1647+ // The std library crates are in
1648+ // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1649+ // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1650+ // detect crates from the std libs and handle them specially.
1651+ const STD_LIBS : & [ & str ] = & [
1652+ "core" ,
1653+ "alloc" ,
1654+ "std" ,
1655+ "test" ,
1656+ "term" ,
1657+ "unwind" ,
1658+ "proc_macro" ,
1659+ "panic_abort" ,
1660+ "panic_unwind" ,
1661+ "profiler_builtins" ,
1662+ "rtstartup" ,
1663+ "rustc-std-workspace-core" ,
1664+ "rustc-std-workspace-alloc" ,
1665+ "rustc-std-workspace-std" ,
1666+ "backtrace" ,
1667+ ] ;
1668+ let is_std_lib =
1669+ STD_LIBS . iter ( ) . any ( |l| rest. starts_with ( l) ) ;
1670+
1671+ let new_path = if is_std_lib {
1672+ real_dir. join ( "library" ) . join ( rest)
1673+ } else {
1674+ real_dir. join ( rest)
1675+ } ;
1676+
1677+ debug ! (
1678+ "try_to_translate_virtual_to_real: `{}` -> `{}`" ,
1679+ virtual_name. display( ) ,
1680+ new_path. display( ) ,
1681+ ) ;
1682+ let new_name = rustc_span:: RealFileName :: Devirtualized {
1683+ local_path : new_path,
1684+ virtual_name,
1685+ } ;
1686+ * old_name = new_name;
1687+ * name_hash = name. name_hash ( ) ;
1688+ }
16861689 }
16871690 }
16881691 }
16891692 }
1690- }
1691- } ;
1693+ } ;
16921694
1693- self . cdata . source_map_import_info . get_or_init ( || {
16941695 let external_source_map = self . root . source_map . decode ( self ) ;
16951696
16961697 external_source_map
0 commit comments