Skip to content

Commit 090843a

Browse files
committed
Implement RFC 3127 sysroot handling
1 parent e480904 commit 090843a

File tree

4 files changed

+128
-50
lines changed

4 files changed

+128
-50
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,56 +1597,50 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15971597
);
15981598

15991599
for virtual_dir in virtual_rust_source_base_dir.iter().flatten() {
1600-
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1601-
if let rustc_span::FileName::Real(old_name) = name {
1602-
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1603-
old_name
1604-
{
1605-
if let Ok(rest) = virtual_name.strip_prefix(virtual_dir) {
1606-
let virtual_name = virtual_name.clone();
1607-
1608-
// The std library crates are in
1609-
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1610-
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1611-
// detect crates from the std libs and handle them specially.
1612-
const STD_LIBS: &[&str] = &[
1613-
"core",
1614-
"alloc",
1615-
"std",
1616-
"test",
1617-
"term",
1618-
"unwind",
1619-
"proc_macro",
1620-
"panic_abort",
1621-
"panic_unwind",
1622-
"profiler_builtins",
1623-
"rtstartup",
1624-
"rustc-std-workspace-core",
1625-
"rustc-std-workspace-alloc",
1626-
"rustc-std-workspace-std",
1627-
"backtrace",
1628-
];
1629-
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1630-
1631-
let new_path = if is_std_lib {
1632-
real_dir.join("library").join(rest)
1633-
} else {
1634-
real_dir.join(rest)
1635-
};
1636-
1637-
debug!(
1638-
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1639-
virtual_name.display(),
1640-
new_path.display(),
1641-
);
1642-
let new_name = rustc_span::RealFileName::Remapped {
1643-
local_path: Some(new_path),
1644-
virtual_name,
1645-
};
1646-
*old_name = new_name;
1647-
}
1648-
}
1649-
}
1600+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir
1601+
&& let rustc_span::FileName::Real(old_name) = name
1602+
&& let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1603+
old_name
1604+
&& let Ok(rest) = virtual_name.strip_prefix(virtual_dir)
1605+
{
1606+
let virtual_name = virtual_name.clone();
1607+
1608+
// The std library crates are in
1609+
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1610+
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1611+
// detect crates from the std libs and handle them specially.
1612+
const STD_LIBS: &[&str] = &[
1613+
"core",
1614+
"alloc",
1615+
"std",
1616+
"test",
1617+
"term",
1618+
"unwind",
1619+
"proc_macro",
1620+
"panic_abort",
1621+
"panic_unwind",
1622+
"profiler_builtins",
1623+
"rtstartup",
1624+
"rustc-std-workspace-core",
1625+
"rustc-std-workspace-alloc",
1626+
"rustc-std-workspace-std",
1627+
"backtrace",
1628+
];
1629+
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1630+
1631+
let new_path = if is_std_lib {
1632+
real_dir.join("library").join(rest)
1633+
} else {
1634+
real_dir.join(rest)
1635+
};
1636+
1637+
debug!(
1638+
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1639+
virtual_name.display(),
1640+
new_path.display(),
1641+
);
1642+
let new_name = rustc_span::RealFileName::LocalPath(new_path);
1643+
*old_name = new_name;
16501644
}
16511645
}
16521646
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-fail
2+
// check-run-results
3+
4+
// exec-env:RUST_BACKTRACE=full
5+
// revisions: with-remap without-remap
6+
// compile-flags: -g -Ztranslate-remapped-path-to-local-path=yes
7+
// [with-remap]compile-flags: --remap-path-prefix={{rust-src-base}}=remapped
8+
// [without-remap]compile-flags:
9+
10+
fn main() {
11+
Vec::<String>::with_capacity(!0);
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
thread 'main' panicked at library/alloc/src/raw_vec.rs:545:5:
2+
capacity overflow
3+
stack backtrace:
4+
0: 0x1056a1fb0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h34ddcf7e122b89ac
5+
1: 0x1056f9714 - core::fmt::write::hd1aeea4ff96546ca
6+
2: 0x1056a59e4 - std::io::Write::write_fmt::h17b1090c1278c55b
7+
3: 0x1056a1e20 - std::sys_common::backtrace::print::hfafdd06e00730994
8+
4: 0x1056c218c - std::panicking::default_hook::{{closure}}::h97a3d80e798f2ed6
9+
5: 0x1056c1f6c - std::panicking::default_hook::hda0f04e04c8eb266
10+
6: 0x1056c25d0 - std::panicking::rust_panic_with_hook::hf66d5a2176bf0f70
11+
7: 0x1056a27f4 - std::panicking::begin_panic_handler::{{closure}}::haacaa3525d299c3a
12+
8: 0x1056a21e0 - std::sys_common::backtrace::__rust_end_short_backtrace::h87e6f3e754a75849
13+
9: 0x1056c2334 - _rust_begin_unwind
14+
10: 0x1057167f8 - core::panicking::panic_fmt::h02ef70cf9926e63a
15+
11: 0x1056f45c4 - alloc::raw_vec::capacity_overflow::h4447458ef5d0325b
16+
12: 0x10498b250 - alloc::raw_vec::RawVec<T,A>::allocate_in::he48752b99f53b509
17+
at remapped/library/alloc/src/raw_vec.rs:177:27
18+
13: 0x10498adac - alloc::raw_vec::RawVec<T,A>::with_capacity_in::h0f23d7d992348ac1
19+
at remapped/library/alloc/src/raw_vec.rs:130:9
20+
14: 0x10498adac - alloc::vec::Vec<T,A>::with_capacity_in::h8aa83d89b81dd67c
21+
at remapped/library/alloc/src/vec/mod.rs:670:20
22+
15: 0x10498adac - alloc::vec::Vec<T>::with_capacity::h9bcc7d8009345416
23+
at remapped/library/alloc/src/vec/mod.rs:479:9
24+
16: 0x10498b7ac - remap_path_prefix_sysroot::main::hc6dc31a7bd7adcd2
25+
at remapped/tests/ui/errors/remap-path-prefix-sysroot.rs:11:5
26+
17: 0x10498aa28 - core::ops::function::FnOnce::call_once::hc6cd7e6e6c0a39ec
27+
at remapped/library/core/src/ops/function.rs:250:5
28+
18: 0x10498a938 - std::sys_common::backtrace::__rust_begin_short_backtrace::h00cfadb0500687d9
29+
at remapped/library/std/src/sys_common/backtrace.rs:155:18
30+
19: 0x10498a9cc - std::rt::lang_start::{{closure}}::hdaed3a6f285f5688
31+
at remapped/library/std/src/rt.rs:167:18
32+
20: 0x1056c227c - std::panicking::try::hfb03667ecc24ab29
33+
21: 0x1056ae9e4 - std::rt::lang_start_internal::he5e74d4e4d2cb01e
34+
22: 0x10498a998 - std::rt::lang_start::hdf7d4c5cfb24235f
35+
at remapped/library/std/src/rt.rs:166:17
36+
23: 0x10498b7e4 - _main
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
thread 'main' panicked at library/alloc/src/raw_vec.rs:545:5:
2+
capacity overflow
3+
stack backtrace:
4+
0: 0x103ce1fb0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h34ddcf7e122b89ac
5+
1: 0x103d39714 - core::fmt::write::hd1aeea4ff96546ca
6+
2: 0x103ce59e4 - std::io::Write::write_fmt::h17b1090c1278c55b
7+
3: 0x103ce1e20 - std::sys_common::backtrace::print::hfafdd06e00730994
8+
4: 0x103d0218c - std::panicking::default_hook::{{closure}}::h97a3d80e798f2ed6
9+
5: 0x103d01f6c - std::panicking::default_hook::hda0f04e04c8eb266
10+
6: 0x103d025d0 - std::panicking::rust_panic_with_hook::hf66d5a2176bf0f70
11+
7: 0x103ce27f4 - std::panicking::begin_panic_handler::{{closure}}::haacaa3525d299c3a
12+
8: 0x103ce21e0 - std::sys_common::backtrace::__rust_end_short_backtrace::h87e6f3e754a75849
13+
9: 0x103d02334 - _rust_begin_unwind
14+
10: 0x103d567f8 - core::panicking::panic_fmt::h02ef70cf9926e63a
15+
11: 0x103d345c4 - alloc::raw_vec::capacity_overflow::h4447458ef5d0325b
16+
12: 0x102fcb250 - alloc::raw_vec::RawVec<T,A>::allocate_in::he48752b99f53b509
17+
at $SRC_DIR_REAL/alloc/src/raw_vec.rs:LL:COL
18+
13: 0x102fcadac - alloc::raw_vec::RawVec<T,A>::with_capacity_in::h0f23d7d992348ac1
19+
at $SRC_DIR_REAL/alloc/src/raw_vec.rs:LL:COL
20+
14: 0x102fcadac - alloc::vec::Vec<T,A>::with_capacity_in::h8aa83d89b81dd67c
21+
at $SRC_DIR_REAL/alloc/src/vec/mod.rs:LL:COL
22+
15: 0x102fcadac - alloc::vec::Vec<T>::with_capacity::h9bcc7d8009345416
23+
at $SRC_DIR_REAL/alloc/src/vec/mod.rs:LL:COL
24+
16: 0x102fcb7ac - remap_path_prefix_sysroot::main::hc6dc31a7bd7adcd2
25+
at $DIR/remap-path-prefix-sysroot.rs:11:5
26+
17: 0x102fcaa28 - core::ops::function::FnOnce::call_once::hc6cd7e6e6c0a39ec
27+
at $SRC_DIR_REAL/core/src/ops/function.rs:LL:COL
28+
18: 0x102fca938 - std::sys_common::backtrace::__rust_begin_short_backtrace::h00cfadb0500687d9
29+
at $SRC_DIR_REAL/std/src/sys_common/backtrace.rs:LL:COL
30+
19: 0x102fca9cc - std::rt::lang_start::{{closure}}::hdaed3a6f285f5688
31+
at $SRC_DIR_REAL/std/src/rt.rs:LL:COL
32+
20: 0x103d0227c - std::panicking::try::hfb03667ecc24ab29
33+
21: 0x103cee9e4 - std::rt::lang_start_internal::he5e74d4e4d2cb01e
34+
22: 0x102fca998 - std::rt::lang_start::hdf7d4c5cfb24235f
35+
at $SRC_DIR_REAL/std/src/rt.rs:LL:COL
36+
23: 0x102fcb7e4 - _main

0 commit comments

Comments
 (0)