Skip to content

Commit

Permalink
Make local_crate_source_file depends on a remap path scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Mar 18, 2024
1 parent 4fa0013 commit 4cfbe65
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
15 changes: 8 additions & 7 deletions compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ impl DebugContext {
FileNameDisplayPreference::Local
})
.into_owned();
let (name, file_info) = match tcx.sess.local_crate_source_file() {
Some(path) => {
let name = path.to_string_lossy().into_owned();
(name, None)
}
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
};
let (name, file_info) =
match tcx.sess.local_crate_source_file(RemapPathScopeComponents::DEBUGINFO) {
Some(path) => {
let name = path.to_string_lossy().into_owned();
(name, None)
}
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
};

let mut line_program = LineProgram::new(
encoding,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
) -> &'ll DIDescriptor {
let mut name_in_debuginfo = tcx
.sess
.local_crate_source_file()
.local_crate_source_file(RemapPathScopeComponents::DEBUGINFO)
.unwrap_or_else(|| PathBuf::from(tcx.crate_name(LOCAL_CRATE).as_str()));

// To avoid breaking split DWARF, we need to ensure that each codegen unit
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::{ItemId, Node, CRATE_HIR_ID};
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{sigpipe, CrateType, EntryFnType};
use rustc_session::config::{sigpipe, CrateType, EntryFnType, RemapPathScopeComponents};
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
Expand Down Expand Up @@ -176,10 +176,13 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {

// There is no main function.
let mut has_filename = true;
let filename = tcx.sess.local_crate_source_file().unwrap_or_else(|| {
has_filename = false;
Default::default()
});
let filename = tcx
.sess
.local_crate_source_file(RemapPathScopeComponents::DIAGNOSTICS)
.unwrap_or_else(|| {
has_filename = false;
Default::default()
});
let main_def_opt = tcx.resolutions(()).main_def;
let code = E0601;
let add_teach_note = tcx.sess.teach(code);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ impl Session {
self.miri_unleashed_features.lock().push((span, feature_gate));
}

pub fn local_crate_source_file(&self) -> Option<PathBuf> {
pub fn local_crate_source_file(&self, scope: RemapPathScopeComponents) -> Option<PathBuf> {
let path = self.io.input.opt_path()?;
// FIXME: The remap path scope should probably not be hardcoded.
if self.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
if self.should_prefer_remapped(scope) {
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
} else {
Some(path.to_path_buf())
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_hir::Mutability;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::config::RemapPathScopeComponents;
use rustc_session::RustcVersion;
use rustc_span::{
symbol::{sym, Symbol},
Expand Down Expand Up @@ -2506,7 +2507,8 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
// Look for the example file in the source map if it exists, otherwise return a dummy span
let file_span = (|| {
let source_map = tcx.sess.source_map();
let crate_src = tcx.sess.local_crate_source_file()?;
let crate_src =
tcx.sess.local_crate_source_file(RemapPathScopeComponents::DIAGNOSTICS)?;
let abs_crate_src = crate_src.canonicalize().ok()?;
let crate_root = abs_crate_src.parent()?.parent()?;
let rel_path = path.strip_prefix(crate_root).ok()?;
Expand Down

0 comments on commit 4cfbe65

Please sign in to comment.