@@ -1622,56 +1622,63 @@ impl<'a> CrateMetadataRef<'a> {
1622
1622
) ;
1623
1623
1624
1624
for virtual_dir in virtual_rust_source_base_dir. iter ( ) . flatten ( ) {
1625
- if let Some ( real_dir) = & sess. opts . real_rust_source_base_dir {
1626
- if let rustc_span:: FileName :: Real ( old_name) = name {
1627
- if let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
1628
- old_name
1629
- {
1630
- if let Ok ( rest) = virtual_name. strip_prefix ( virtual_dir) {
1631
- let virtual_name = virtual_name. clone ( ) ;
1632
-
1633
- // The std library crates are in
1634
- // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1635
- // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1636
- // detect crates from the std libs and handle them specially.
1637
- const STD_LIBS : & [ & str ] = & [
1638
- "core" ,
1639
- "alloc" ,
1640
- "std" ,
1641
- "test" ,
1642
- "term" ,
1643
- "unwind" ,
1644
- "proc_macro" ,
1645
- "panic_abort" ,
1646
- "panic_unwind" ,
1647
- "profiler_builtins" ,
1648
- "rtstartup" ,
1649
- "rustc-std-workspace-core" ,
1650
- "rustc-std-workspace-alloc" ,
1651
- "rustc-std-workspace-std" ,
1652
- "backtrace" ,
1653
- ] ;
1654
- let is_std_lib = STD_LIBS . iter ( ) . any ( |l| rest. starts_with ( l) ) ;
1655
-
1656
- let new_path = if is_std_lib {
1657
- real_dir. join ( "library" ) . join ( rest)
1658
- } else {
1659
- real_dir. join ( rest)
1660
- } ;
1661
-
1662
- debug ! (
1663
- "try_to_translate_virtual_to_real: `{}` -> `{}`" ,
1664
- virtual_name. display( ) ,
1665
- new_path. display( ) ,
1666
- ) ;
1667
- let new_name = rustc_span:: RealFileName :: Remapped {
1668
- local_path : Some ( new_path) ,
1669
- virtual_name,
1670
- } ;
1671
- * old_name = new_name;
1672
- }
1625
+ if let Some ( real_dir) = & sess. opts . real_rust_source_base_dir
1626
+ && let rustc_span:: FileName :: Real ( old_name) = name
1627
+ && let rustc_span:: RealFileName :: Remapped { local_path : _, virtual_name } =
1628
+ old_name
1629
+ && let Ok ( rest) = virtual_name. strip_prefix ( virtual_dir)
1630
+ {
1631
+ // The std library crates are in
1632
+ // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1633
+ // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1634
+ // detect crates from the std libs and handle them specially.
1635
+ const STD_LIBS : & [ & str ] = & [
1636
+ "core" ,
1637
+ "alloc" ,
1638
+ "std" ,
1639
+ "test" ,
1640
+ "term" ,
1641
+ "unwind" ,
1642
+ "proc_macro" ,
1643
+ "panic_abort" ,
1644
+ "panic_unwind" ,
1645
+ "profiler_builtins" ,
1646
+ "rtstartup" ,
1647
+ "rustc-std-workspace-core" ,
1648
+ "rustc-std-workspace-alloc" ,
1649
+ "rustc-std-workspace-std" ,
1650
+ "backtrace" ,
1651
+ ] ;
1652
+ let is_std_lib = STD_LIBS . iter ( ) . any ( |l| rest. starts_with ( l) ) ;
1653
+
1654
+ let new_path = if is_std_lib {
1655
+ real_dir. join ( "library" ) . join ( rest)
1656
+ } else {
1657
+ real_dir. join ( rest)
1658
+ } ;
1659
+
1660
+ debug ! (
1661
+ "try_to_translate_virtual_to_real: `{}` -> `{}`" ,
1662
+ virtual_name. display( ) ,
1663
+ new_path. display( ) ,
1664
+ ) ;
1665
+
1666
+ // Check if the translated real path is affected by any user-requested
1667
+ // remaps via --remap-path-prefix. Apply them if so.
1668
+ // Note that this is a special case for imported rust-src paths specified by
1669
+ // https://rust-lang.github.io/rfcs/3127-trim-paths.html#handling-sysroot-paths.
1670
+ // Other imported paths are not currently remapped (see #66251).
1671
+ let ( user_remapped, applied) =
1672
+ sess. source_map ( ) . path_mapping ( ) . map_prefix ( & new_path) ;
1673
+ let new_name = if applied {
1674
+ rustc_span:: RealFileName :: Remapped {
1675
+ local_path : Some ( new_path. clone ( ) ) ,
1676
+ virtual_name : user_remapped. to_path_buf ( ) ,
1673
1677
}
1674
- }
1678
+ } else {
1679
+ rustc_span:: RealFileName :: LocalPath ( new_path)
1680
+ } ;
1681
+ * old_name = new_name;
1675
1682
}
1676
1683
}
1677
1684
} ;
0 commit comments