Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply simulate-remapped-rust-src-base even if remap-debuginfo is set in config.toml #110699

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,28 +1458,30 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
..
} = source_file_to_import;

// If this file is under $sysroot/lib/rustlib/src/ but has not been remapped
// during rust bootstrapping by `remap-debuginfo = true`, and the user
// wish to simulate that behaviour by -Z simulate-remapped-rust-src-base,
// If this file is under $sysroot/lib/rustlib/src/
// and the user wish to simulate remapping with -Z simulate-remapped-rust-src-base,
// then we change `name` to a similar state as if the rust was bootstrapped
// with `remap-debuginfo = true`.
// This is useful for testing so that tests about the effects of
// `try_to_translate_virtual_to_real` don't have to worry about how the
// compiler is bootstrapped.
if let Some(virtual_dir) = &sess.opts.unstable_opts.simulate_remapped_rust_src_base
{
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
for subdir in ["library", "compiler"] {
if let rustc_span::FileName::Real(ref mut old_name) = name {
if let rustc_span::RealFileName::LocalPath(local) = old_name {
if let Ok(rest) = local.strip_prefix(real_dir.join(subdir)) {
*old_name = rustc_span::RealFileName::Remapped {
local_path: None,
virtual_name: virtual_dir.join(subdir).join(rest),
};
}
}
}
&& let Some(real_dir) = &sess.opts.real_rust_source_base_dir
&& let rustc_span::FileName::Real(ref mut old_name) = name {
let relative_path = match old_name {
rustc_span::RealFileName::LocalPath(local) => local.strip_prefix(real_dir).ok(),
rustc_span::RealFileName::Remapped { virtual_name, .. } => {
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").and_then(|virtual_dir| virtual_name.strip_prefix(virtual_dir).ok())
}
};
debug!(?relative_path, ?virtual_dir, "simulate_remapped_rust_src_base");
for subdir in ["library", "compiler"] {
if let Some(rest) = relative_path.and_then(|p| p.strip_prefix(subdir).ok()) {
*old_name = rustc_span::RealFileName::Remapped {
local_path: None, // FIXME: maybe we should preserve this?
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
virtual_name: virtual_dir.join(subdir).join(rest),
};
break;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/track-diagnostics/track6.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// compile-flags: -Z track-diagnostics
// error-pattern: created at

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


pub trait Foo {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/track-diagnostics/track6.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0658]: specialization is unstable
--> $DIR/track6.rs:11:5
--> $DIR/track6.rs:LL:CC
|
LL | default fn bar() {}
| ^^^^^^^^^^^^^^^^^^^
-Ztrack-diagnostics: created at $COMPILER_DIR/rustc_session/src/parse.rs:93:5
-Ztrack-diagnostics: created at $COMPILER_DIR/rustc_session/src/parse.rs:LL:CC
|
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: add `#![feature(specialization)]` to the crate attributes to enable
Expand Down