Skip to content

Commit e4a6f48

Browse files
committed
Make local_crate_source_file depends on a remap path scope
1 parent 1be70c3 commit e4a6f48

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ impl DebugContext {
7777
FileNameDisplayPreference::Local
7878
})
7979
.into_owned();
80-
let (name, file_info) = match tcx.sess.local_crate_source_file() {
81-
Some(path) => {
82-
let name = path.to_string_lossy().into_owned();
83-
(name, None)
84-
}
85-
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
86-
};
80+
let (name, file_info) =
81+
match tcx.sess.local_crate_source_file(RemapPathScopeComponents::DEBUGINFO) {
82+
Some(path) => {
83+
let name = path.to_string_lossy().into_owned();
84+
(name, None)
85+
}
86+
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
87+
};
8788

8889
let mut line_program = LineProgram::new(
8990
encoding,

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
840840
) -> &'ll DIDescriptor {
841841
let mut name_in_debuginfo = tcx
842842
.sess
843-
.local_crate_source_file()
843+
.local_crate_source_file(RemapPathScopeComponents::DEBUGINFO)
844844
.unwrap_or_else(|| PathBuf::from(tcx.crate_name(LOCAL_CRATE).as_str()));
845845

846846
// To avoid breaking split DWARF, we need to ensure that each codegen unit

compiler/rustc_passes/src/entry.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
66
use rustc_hir::{ItemId, Node, CRATE_HIR_ID};
77
use rustc_middle::query::Providers;
88
use rustc_middle::ty::TyCtxt;
9-
use rustc_session::config::{sigpipe, CrateType, EntryFnType};
9+
use rustc_session::config::{sigpipe, CrateType, EntryFnType, RemapPathScopeComponents};
1010
use rustc_session::parse::feature_err;
1111
use rustc_span::symbol::sym;
1212
use rustc_span::{Span, Symbol};
@@ -176,10 +176,13 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
176176

177177
// There is no main function.
178178
let mut has_filename = true;
179-
let filename = tcx.sess.local_crate_source_file().unwrap_or_else(|| {
180-
has_filename = false;
181-
Default::default()
182-
});
179+
let filename = tcx
180+
.sess
181+
.local_crate_source_file(RemapPathScopeComponents::DIAGNOSTICS)
182+
.unwrap_or_else(|| {
183+
has_filename = false;
184+
Default::default()
185+
});
183186
let main_def_opt = tcx.resolutions(()).main_def;
184187
let code = E0601;
185188
let add_teach_note = tcx.sess.teach(code);

compiler/rustc_session/src/session.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ impl Session {
250250
self.miri_unleashed_features.lock().push((span, feature_gate));
251251
}
252252

253-
pub fn local_crate_source_file(&self) -> Option<PathBuf> {
253+
pub fn local_crate_source_file(&self, scope: RemapPathScopeComponents) -> Option<PathBuf> {
254254
let path = self.io.input.opt_path()?;
255-
// FIXME: The remap path scope should probably not be hardcoded.
256-
if self.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
255+
if self.should_prefer_remapped(scope) {
257256
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
258257
} else {
259258
Some(path.to_path_buf())

src/librustdoc/html/render/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5353
use rustc_hir::def_id::{DefId, DefIdSet};
5454
use rustc_hir::Mutability;
5555
use rustc_middle::ty::{self, TyCtxt};
56+
use rustc_session::config::RemapPathScopeComponents;
5657
use rustc_session::RustcVersion;
5758
use rustc_span::{
5859
symbol::{sym, Symbol},
@@ -2506,7 +2507,8 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
25062507
// Look for the example file in the source map if it exists, otherwise return a dummy span
25072508
let file_span = (|| {
25082509
let source_map = tcx.sess.source_map();
2509-
let crate_src = tcx.sess.local_crate_source_file()?;
2510+
let crate_src =
2511+
tcx.sess.local_crate_source_file(RemapPathScopeComponents::DIAGNOSTICS)?;
25102512
let abs_crate_src = crate_src.canonicalize().ok()?;
25112513
let crate_root = abs_crate_src.parent()?.parent()?;
25122514
let rel_path = path.strip_prefix(crate_root).ok()?;

0 commit comments

Comments
 (0)