Skip to content

Commit 4dcb816

Browse files
committed
Fix -Zremap-path-scope rmeta handling
1 parent 0c478fd commit 4dcb816

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use rustc_middle::ty::fast_reject::{self, TreatParams};
2626
use rustc_middle::ty::{AssocItemContainer, SymbolName};
2727
use rustc_middle::{bug, span_bug};
2828
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
29-
use rustc_session::config::{CrateType, OptLevel, TargetModifier};
29+
use rustc_session::config::{CrateType, OptLevel, RemapPathScopeComponents, TargetModifier};
3030
use rustc_span::hygiene::HygieneEncodeContext;
3131
use rustc_span::{
32-
ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId, SyntaxContext,
33-
sym,
32+
ExternalSource, FileName, FileNameDisplayPreference, SourceFile, SpanData, SpanEncoder,
33+
StableSourceFileId, SyntaxContext, sym,
3434
};
3535
use tracing::{debug, instrument, trace};
3636

@@ -520,6 +520,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
520520
let source_map = self.tcx.sess.source_map();
521521
let all_source_files = source_map.files();
522522

523+
let filename_display_preference =
524+
self.tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
525+
523526
// By replacing the `Option` with `None`, we ensure that we can't
524527
// accidentally serialize any more `Span`s after the source map encoding
525528
// is done.
@@ -551,11 +554,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
551554

552555
match source_file.name {
553556
FileName::Real(ref original_file_name) => {
554-
// FIXME: This should probably to conditionally remapped under
555-
// a RemapPathScopeComponents but which one?
556-
let adapted_file_name = source_map
557-
.path_mapping()
558-
.to_embeddable_absolute_path(original_file_name.clone(), working_directory);
557+
let adapted_file_name =
558+
if filename_display_preference == FileNameDisplayPreference::Remapped {
559+
source_map.path_mapping().to_embeddable_absolute_path(
560+
original_file_name.clone(),
561+
working_directory,
562+
)
563+
} else {
564+
source_map.path_mapping().to_local_embeddable_absolute_path(
565+
original_file_name.clone(),
566+
working_directory,
567+
)
568+
};
559569

560570
adapted_source_file.name = FileName::Real(adapted_file_name);
561571
}

tests/run-make/remap-path-prefix/rmake.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ fn main() {
4949
rmeta_contains("/the/aux/lib.rs");
5050
rmeta_not_contains("auxiliary");
5151
out_macro.run();
52-
rmeta_contains("/the/aux/lib.rs");
53-
rmeta_not_contains("auxiliary");
52+
rmeta_not_contains("/the/aux/lib.rs");
53+
rmeta_contains("auxiliary");
5454
out_diagobj.run();
5555
rmeta_contains("/the/aux/lib.rs");
5656
rmeta_not_contains("auxiliary");
5757
}
5858

5959
//FIXME(Oneirical): These could be generalized into run_make_support
6060
// helper functions.
61+
#[track_caller]
6162
fn rmeta_contains(expected: &str) {
6263
// Normalize to account for path differences in Windows.
6364
if !bstr::BString::from(rfs::read("liblib.rmeta")).replace(b"\\", b"/").contains_str(expected) {
@@ -69,6 +70,7 @@ fn rmeta_contains(expected: &str) {
6970
}
7071
}
7172

73+
#[track_caller]
7274
fn rmeta_not_contains(expected: &str) {
7375
// Normalize to account for path differences in Windows.
7476
if bstr::BString::from(rfs::read("liblib.rmeta")).replace(b"\\", b"/").contains_str(expected) {

0 commit comments

Comments
 (0)