Skip to content

Commit 0407919

Browse files
committed
Use RealFileName for Session::working_dir as it may also be remapped
1 parent 9e0426d commit 0407919

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> DebugContext<'tcx> {
6464
// FIXME: how to get version when building out of tree?
6565
// Normally this would use option_env!("CFG_VERSION").
6666
let producer = format!("cg_clif (rustc {})", "unknown version");
67-
let comp_dir = tcx.sess.working_dir.0.to_string_lossy().into_owned();
67+
let comp_dir = tcx.sess.working_dir.stable_name().to_string_lossy().into_owned();
6868
let (name, file_info) = match tcx.sess.local_crate_source_file.clone() {
6969
Some(path) => {
7070
let name = path.to_string_lossy().into_owned();

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ pub fn file_metadata(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll
764764
let hash = Some(&source_file.src_hash);
765765
let file_name = Some(source_file.name.to_string());
766766
let directory = if source_file.is_real_file() && !source_file.is_imported() {
767-
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
767+
Some(cx.sess().working_dir.stable_name().to_string_lossy().to_string())
768768
} else {
769769
// If the path comes from an upstream crate we assume it has been made
770770
// independent of the compiler's working directory one way or another.
@@ -992,7 +992,7 @@ pub fn compile_unit_metadata(
992992
let producer = format!("clang LLVM ({})", rustc_producer);
993993

994994
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
995-
let work_dir = tcx.sess.working_dir.0.to_string_lossy();
995+
let work_dir = tcx.sess.working_dir.stable_name().to_string_lossy();
996996
let flags = "\0";
997997
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
998998
let split_name = if tcx.sess.target_can_use_split_dwarf() {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
469469
let source_map = self.tcx.sess.source_map();
470470
let all_source_files = source_map.files();
471471

472-
let (working_dir, _cwd_remapped) = self.tcx.sess.working_dir.clone();
472+
let working_dir = self.tcx.sess.working_dir.stable_name();
473473
// By replacing the `Option` with `None`, we ensure that we can't
474474
// accidentally serialize any more `Span`s after the source map encoding
475475
// is done.

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'tcx> DumpVisitor<'tcx> {
190190
};
191191

192192
let data = CompilationOptions {
193-
directory: self.tcx.sess.working_dir.0.clone(),
193+
directory: self.tcx.sess.working_dir.stable_name().into(),
194194
program,
195195
arguments,
196196
output: self.save_ctxt.compilation_output(crate_name),

compiler/rustc_save_analysis/src/span_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a> SpanUtils<'a> {
2626
.display()
2727
.to_string()
2828
} else {
29-
self.sess.working_dir.0.join(&path).display().to_string()
29+
self.sess.working_dir.stable_name().join(&path).display().to_string()
3030
}
3131
}
3232
// If the file name was remapped, we assume the user

compiler/rustc_session/src/session.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use rustc_errors::registry::Registry;
2323
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
2424
use rustc_lint_defs::FutureBreakage;
2525
pub use rustc_span::crate_disambiguator::CrateDisambiguator;
26-
use rustc_span::edition::Edition;
2726
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
27+
use rustc_span::{edition::Edition, RealFileName};
2828
use rustc_span::{sym, SourceFileHashAlgorithm, Symbol};
2929
use rustc_target::asm::InlineAsmArch;
3030
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
@@ -125,9 +125,8 @@ pub struct Session {
125125
/// The name of the root source file of the crate, in the local file system.
126126
/// `None` means that there is no source file.
127127
pub local_crate_source_file: Option<PathBuf>,
128-
/// The directory the compiler has been executed in plus a flag indicating
129-
/// if the value stored here has been affected by path remapping.
130-
pub working_dir: (PathBuf, bool),
128+
/// The directory the compiler has been executed in
129+
pub working_dir: RealFileName,
131130

132131
/// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking
133132
/// (sub)diagnostics that have been set once, but should not be set again,
@@ -1361,7 +1360,12 @@ pub fn build_session(
13611360
let working_dir = env::current_dir().unwrap_or_else(|e| {
13621361
parse_sess.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e)).raise()
13631362
});
1364-
let working_dir = file_path_mapping.map_prefix(working_dir);
1363+
let (path, remapped) = file_path_mapping.map_prefix(working_dir.clone());
1364+
let working_dir = if remapped {
1365+
RealFileName::Remapped { local_path: Some(working_dir), virtual_name: path }
1366+
} else {
1367+
RealFileName::LocalPath(path)
1368+
};
13651369

13661370
let cgu_reuse_tracker = if sopts.debugging_opts.query_dep_graph {
13671371
CguReuseTracker::new()

0 commit comments

Comments
 (0)