Skip to content

Commit ebf2b37

Browse files
committed
Auto merge of rust-lang#110699 - jyn514:simulate-remapped-already-remapped, r=cjgillot
Apply simulate-remapped-rust-src-base even if remap-debuginfo is set in config.toml This is really a mess. Here is the situation before this change: - UI tests depend on not having `rust-src` available. In particular, <https://github.com/rust-lang/rust/blob/3f374128ee3924514aacadf96479e17fee8f9903/tests/ui/tuple/wrong_argument_ice.stderr#L7-L8> is depending on the `note` being a single line and not showing the source code. - When `download-rustc` is disabled, we pass `-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX` `-Ztranslate-remapped-path-to-local-path=no`, which changes the diagnostic to something like ` --> /rustc/FAKE_PREFIX/library/alloc/src/collections/vec_deque/mod.rs:1657:12` - When `download-rustc` is enabled, we still pass those flags, but they no longer have an effect. Instead rustc emits diagnostic paths like this: ` --> /rustc/39c6804b92aa202369e402525cee329556bc1db0/library/alloc/src/collections/vec_deque/mod.rs:1657:12`. Notice how there's a real commit and not `FAKE_PREFIX`. This happens because we set `CFG_VIRTUAL_RUST_SOURCE_BASE_DIR` during bootstrapping for CI artifacts, and rustc previously didn't allow for `simulate-remapped` to affect paths that had already been remapped. - Pietro noticed this and decided the right thing was to normalize `/rustc/<commit>` to `$SRC_DIR` in compiletest: rust-lang@470423c - After my change to `x test core`, which rebuilds stage 2 std from source so `build/stage2-std` and `build/stage2` use the same `.rlib` metadata, the compiler suddenly notices it has sources for `std` available and prints those in the diagnostic, causing the test to fail. This changes `simulate-remapped-rust-src-base` to support remapping paths that have already been remapped, unblocking download-rustc. Unfortunately, although this fixes the specific problem for download-rustc, it doesn't seem to affect all the compiler's diagnostics. In particular, various `mir-opt` tests are failing to respect `simulate-remapped-path-prefix` (I looked into fixing this but it seems non-trivial). As a result, we can't remove the normalization in compiletest that maps `/rustc/<commit>` to `$SRC_DIR`, so this change is currently untested anywhere except locally. You can test this locally yourself by setting `rust.remap-debuginfo = true`, running any UI test with `ERROR` annotations, then rerunning the test manually with a dev toolchain to verify it prints `/rustc/FAKE_PREFIX`, not `/rustc/1.71.0`. Helps with rust-lang#110352.
2 parents 69fef92 + 8785615 commit ebf2b37

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1472,28 +1472,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14721472
..
14731473
} = source_file_to_import;
14741474

1475-
// If this file is under $sysroot/lib/rustlib/src/ but has not been remapped
1476-
// during rust bootstrapping by `remap-debuginfo = true`, and the user
1477-
// wish to simulate that behaviour by -Z simulate-remapped-rust-src-base,
1475+
// If this file is under $sysroot/lib/rustlib/src/
1476+
// and the user wish to simulate remapping with -Z simulate-remapped-rust-src-base,
14781477
// then we change `name` to a similar state as if the rust was bootstrapped
14791478
// with `remap-debuginfo = true`.
14801479
// This is useful for testing so that tests about the effects of
14811480
// `try_to_translate_virtual_to_real` don't have to worry about how the
14821481
// compiler is bootstrapped.
14831482
if let Some(virtual_dir) = &sess.opts.unstable_opts.simulate_remapped_rust_src_base
1484-
{
1485-
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1486-
for subdir in ["library", "compiler"] {
1487-
if let rustc_span::FileName::Real(ref mut old_name) = name {
1488-
if let rustc_span::RealFileName::LocalPath(local) = old_name {
1489-
if let Ok(rest) = local.strip_prefix(real_dir.join(subdir)) {
1490-
*old_name = rustc_span::RealFileName::Remapped {
1491-
local_path: None,
1492-
virtual_name: virtual_dir.join(subdir).join(rest),
1493-
};
1494-
}
1495-
}
1496-
}
1483+
&& let Some(real_dir) = &sess.opts.real_rust_source_base_dir
1484+
&& let rustc_span::FileName::Real(ref mut old_name) = name {
1485+
let relative_path = match old_name {
1486+
rustc_span::RealFileName::LocalPath(local) => local.strip_prefix(real_dir).ok(),
1487+
rustc_span::RealFileName::Remapped { virtual_name, .. } => {
1488+
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").and_then(|virtual_dir| virtual_name.strip_prefix(virtual_dir).ok())
1489+
}
1490+
};
1491+
debug!(?relative_path, ?virtual_dir, "simulate_remapped_rust_src_base");
1492+
for subdir in ["library", "compiler"] {
1493+
if let Some(rest) = relative_path.and_then(|p| p.strip_prefix(subdir).ok()) {
1494+
*old_name = rustc_span::RealFileName::Remapped {
1495+
local_path: None, // FIXME: maybe we should preserve this?
1496+
virtual_name: virtual_dir.join(subdir).join(rest),
1497+
};
1498+
break;
14971499
}
14981500
}
14991501
}

tests/ui/track-diagnostics/track6.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// compile-flags: -Z track-diagnostics
22
// error-pattern: created at
33

4+
// Normalize the emitted location so this doesn't need
5+
// updating everytime someone adds or removes a line.
6+
// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"
47

58

69
pub trait Foo {

tests/ui/track-diagnostics/track6.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0658]: specialization is unstable
2-
--> $DIR/track6.rs:11:5
2+
--> $DIR/track6.rs:LL:CC
33
|
44
LL | default fn bar() {}
55
| ^^^^^^^^^^^^^^^^^^^
6-
-Ztrack-diagnostics: created at $COMPILER_DIR/rustc_session/src/parse.rs:93:5
6+
-Ztrack-diagnostics: created at $COMPILER_DIR/rustc_session/src/parse.rs:LL:CC
77
|
88
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
99
= help: add `#![feature(specialization)]` to the crate attributes to enable

0 commit comments

Comments
 (0)