Skip to content

Commit 4780f7d

Browse files
committed
Implement RFC 3127 sysroot handling
1 parent a013915 commit 4780f7d

File tree

4 files changed

+127
-50
lines changed

4 files changed

+127
-50
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+43-50
Original file line numberDiff line numberDiff line change
@@ -1605,56 +1605,49 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16051605
);
16061606

16071607
for virtual_dir in virtual_rust_source_base_dir.iter().flatten() {
1608-
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1609-
if let rustc_span::FileName::Real(old_name) = name {
1610-
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1611-
old_name
1612-
{
1613-
if let Ok(rest) = virtual_name.strip_prefix(virtual_dir) {
1614-
let virtual_name = virtual_name.clone();
1615-
1616-
// The std library crates are in
1617-
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1618-
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1619-
// detect crates from the std libs and handle them specially.
1620-
const STD_LIBS: &[&str] = &[
1621-
"core",
1622-
"alloc",
1623-
"std",
1624-
"test",
1625-
"term",
1626-
"unwind",
1627-
"proc_macro",
1628-
"panic_abort",
1629-
"panic_unwind",
1630-
"profiler_builtins",
1631-
"rtstartup",
1632-
"rustc-std-workspace-core",
1633-
"rustc-std-workspace-alloc",
1634-
"rustc-std-workspace-std",
1635-
"backtrace",
1636-
];
1637-
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1638-
1639-
let new_path = if is_std_lib {
1640-
real_dir.join("library").join(rest)
1641-
} else {
1642-
real_dir.join(rest)
1643-
};
1644-
1645-
debug!(
1646-
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1647-
virtual_name.display(),
1648-
new_path.display(),
1649-
);
1650-
let new_name = rustc_span::RealFileName::Remapped {
1651-
local_path: Some(new_path),
1652-
virtual_name,
1653-
};
1654-
*old_name = new_name;
1655-
}
1656-
}
1657-
}
1608+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir
1609+
&& let rustc_span::FileName::Real(old_name) = name
1610+
&& let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1611+
old_name
1612+
&& let Ok(rest) = virtual_name.strip_prefix(virtual_dir) {
1613+
let virtual_name = virtual_name.clone();
1614+
1615+
// The std library crates are in
1616+
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1617+
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1618+
// detect crates from the std libs and handle them specially.
1619+
const STD_LIBS: &[&str] = &[
1620+
"core",
1621+
"alloc",
1622+
"std",
1623+
"test",
1624+
"term",
1625+
"unwind",
1626+
"proc_macro",
1627+
"panic_abort",
1628+
"panic_unwind",
1629+
"profiler_builtins",
1630+
"rtstartup",
1631+
"rustc-std-workspace-core",
1632+
"rustc-std-workspace-alloc",
1633+
"rustc-std-workspace-std",
1634+
"backtrace",
1635+
];
1636+
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1637+
1638+
let new_path = if is_std_lib {
1639+
real_dir.join("library").join(rest)
1640+
} else {
1641+
real_dir.join(rest)
1642+
};
1643+
1644+
debug!(
1645+
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1646+
virtual_name.display(),
1647+
new_path.display(),
1648+
);
1649+
let new_name = rustc_span::RealFileName::LocalPath(new_path);
1650+
*old_name = new_name;
16581651
}
16591652
}
16601653
};
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+
}
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
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)